swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17k stars 6.03k forks source link

readOnly on nested objects #6537

Open joerghaubrichs opened 7 years ago

joerghaubrichs commented 7 years ago
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
wing328 commented 7 years ago

@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

joerghaubrichs commented 7 years ago

@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.

wing328 commented 7 years ago

😞

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

NikolaySl commented 6 years ago

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 commented 6 years ago

@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 ?

wing328 commented 6 years ago

@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)

twsouthwick commented 6 years ago

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

imissyouso commented 5 years ago

still showing in online swagger hub editor

NadavK commented 4 years ago

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

slifty commented 5 months ago

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.