Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readOnly on nested objects #6537

Open
joerghaubrichs opened this issue Sep 21, 2017 · 10 comments
Open

readOnly on nested objects #6537

joerghaubrichs opened this issue Sep 21, 2017 · 10 comments
Milestone

Comments

@joerghaubrichs
Copy link

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
Copy link
Contributor

wing328 commented Sep 24, 2017

@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 wing328 added this to the Future milestone Sep 24, 2017
@joerghaubrichs
Copy link
Author

@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
Copy link
Contributor

wing328 commented Sep 25, 2017

😞

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

@NikolaySl
Copy link

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 swagger-api/swagger-core#2502 @wing328 Please review and if possible release in 1.5.x branch.

@NikolaySl
Copy link

@wing328 Is there any date scheduled when new version of 1.5 branch of swagger-core will be released with swagger-api/swagger-core#2502 ?

@wing328
Copy link
Contributor

wing328 commented Jan 3, 2018

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

@twsouthwick
Copy link

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

@imissyouso
Copy link

still showing in online swagger hub editor

@NadavK
Copy link

NadavK commented Mar 29, 2020

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

@slifty
Copy link

slifty commented May 15, 2024

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 added a commit to PhilanthropyDataCommons/service that referenced this issue May 16, 2024
Swagger codegen does not currently allow object attributes to be
readOnly directly.  To do this we need to have the object definition be
in a reference [1].  This will have the effect of changing the generated
entity types, but it will also fix a bug where `presignedPost` was
included in the writable form of `PresignedPostRequest`

Issue #1012 WritablePresignedPostRequest improperly requiring readonly property

[1] swagger-api/swagger-codegen#6537
slifty added a commit to PhilanthropyDataCommons/service that referenced this issue May 20, 2024
Swagger codegen does not currently allow object attributes to be
readOnly directly.  To do this we need to have the object definition be
in a reference [1].  This will have the effect of changing the generated
entity types, but it will also fix a bug where `presignedPost` was
included in the writable form of `PresignedPostRequest`

Issue #1012 WritablePresignedPostRequest improperly requiring readonly property

[1] swagger-api/swagger-codegen#6537
slifty added a commit to PhilanthropyDataCommons/service that referenced this issue May 20, 2024
Swagger codegen does not currently allow object attributes to be
readOnly directly.  To do this we need to have the object definition be
in a reference [1].  This will have the effect of changing the generated
entity types, but it will also fix a bug where `presignedPost` was
included in the writable form of `PresignedPostRequest`

Issue #1012 WritablePresignedPostRequest improperly requiring readonly property

[1] swagger-api/swagger-codegen#6537
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants