swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

readOnly on nested objects

Open joerghaubrichs opened this issue 7 years ago • 10 comments

Description

Apparently the readOnly property is ignored for definitions of type object. In my example, SomeDefinition has a property someSubObject, which is an object and should be readOnly. So I would expect someSubObject to be in the list of readOnlyVars for SomeDefinition, but instead I find it in the readWriteVars list.

The other readOnly property, someString, is correctly listed in readOnlyVars and not in readWriteVars.

Is there something wrong with the definition, or is this a bug?

Swagger-codegen version

2.2.3

Swagger declaration file content or url
definitions:
  SomeDefinition:
    type: object
    properties:
      someString:
        readOnly: true
        type: string
      someSubObject:
        readOnly: true
        type: object
        properties:
          someProperty:
            type: string

joerghaubrichs avatar Sep 21 '17 15:09 joerghaubrichs

@joerghaubrichs instead of defining someSubObject inline, have you tried defining it as a reference instead? e.g. https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml#L666

wing328 avatar Sep 24 '17 14:09 wing328

@wing328 Yes, unfortunately. Actually my original problem was using a reference, so I tried to use an object instead to narrow it down and simplify it, but same issue there.

joerghaubrichs avatar Sep 25 '17 08:09 joerghaubrichs

😞

I'll see if I can hunt down the bug this weekend...

wing328 avatar Sep 25 '17 16:09 wing328

It's due to JSON parsing to Swagger model. It doesn't parse 'readOnly' property for references, inline objects, maps and arrays. Here is a PR https://github.com/swagger-api/swagger-core/pull/2502 @wing328 Please review and if possible release in 1.5.x branch.

NikolaySl avatar Nov 02 '17 17:11 NikolaySl

@wing328 Is there any date scheduled when new version of 1.5 branch of swagger-core will be released with https://github.com/swagger-api/swagger-core/pull/2502 ?

NikolaySl avatar Dec 20 '17 19:12 NikolaySl

@NikolaySl https://github.com/swagger-api/swagger-core/pull/2502 has been merged into swagger-core. We'll need to wait for the next release (1.5.18)

wing328 avatar Jan 03 '18 04:01 wing328

@wing328 This is still showing on 2.3.1 of swagger-gen. Looks like 1.5.20 of swagger-core is being used.

twsouthwick avatar Oct 23 '18 19:10 twsouthwick

still showing in online swagger hub editor

imissyouso avatar Jul 17 '19 11:07 imissyouso

See workaround here: https://stackoverflow.com/questions/51402156/how-to-declare-a-ref-property-as-readonly-in-openapi-swagger

NadavK avatar Mar 29 '20 14:03 NadavK

I'm facing this issue now -- I'll give the workarounds a try, but also wanted to see if there are any thoughts on root cause on this since it's been open for some time.

slifty avatar May 15 '24 19:05 slifty