You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AllOf does not respect required for referenced properties #604
Great work on the new allOf rewrite. It generates nearly identical types to the workaround I mentioned here #531 (comment). However, it does not seem to respect the required section for referenced properties. Using the below partial schema:
schemas:
id:
type: stringtitle: iddescription: Unique identifier for the given resource.pattern: '^[a-zA-Z0-9]+$'example: 1qyOUSitRuN5QPSFfVg6AuiUuzFx-go-type: ksuid.KSUIDminLength: 27maxLength: 27readOnly: trueUser:
title: UserallOf:
- type: objectproperties:
id:
$ref: '#/components/schemas/id'required:
- id
- $ref: '#/components/schemas/UserProperties'
- type: objectrequired:
- email
- name
- photo
- verified
We can see it generates the following type:
// User defines model for User.typeUserstruct {
Email openapi_types.Email`json:"email"`// Unique identifier for the given resource.Id*Id`json:"id,omitempty"`// Contains the full name.Namestring`json:"name"`// Link to the gravatar profile photo.Photostring`json:"photo"`Verifiedbool`json:"verified"`
}
Where Email, Name, Photo, and Verified are required but Id is not. Maybe there is some configuration I am missing or this use-case hasn't been taken into account.
In this case we are talking about server side code. A readOnly property that is required should not be a pointer (because it has to be returned by the server).
But what about client side? I think in that case it made sense to have a pointer, because the client should not send the property anyway.
Should we split the objects and have different definitions between client and server?
Relevant only for Schema "properties" definitions. Declares the property as "read only". This means that it MAY be sent as part of a response but SHOULD NOT be sent as part of the request. If the property is marked as readOnly being true and is in the required list, the required will take effect on the response only. A property MUST NOT be marked as both readOnly and writeOnly being true.
However in the 3.1.0 spec, the property definitions follow those of JSON Schema and do not add any additional semantics.
If "readOnly" has a value of boolean true, it indicates that the value of the instance is managed exclusively by the owning authority, and attempts by an application to modify the value of this property are expected to be ignored or rejected by that owning authority.
Activity
florentchauveau commentedon Jun 2, 2022
I was about to post the exact same issue.
That's because your "id" property has "readOnly: true". Readonly properties are generated with pointers.
I am submitting a pull request right now.
Fix readonly+required property
Swiftwork commentedon Jun 2, 2022
Haha perfect, I can confirm that removing readOnly removes the pointer issue.
florentchauveau commentedon Jun 3, 2022
Afterthoughts:
In this case we are talking about server side code. A readOnly property that is required should not be a pointer (because it has to be returned by the server).
But what about client side? I think in that case it made sense to have a pointer, because the client should not send the property anyway.
Should we split the objects and have different definitions between client and server?
florentchauveau commentedon Jun 3, 2022
Here are the relevant parts I found in the specifications:
3.0.3: https://github.com/OAI/OpenAPI-Specification/blob/54edcf039c9854dcbc4feac1b1990c21972f3ca5/versions/3.0.3.md#properties
However in the 3.1.0 spec, the property definitions follow those of JSON Schema and do not add any additional semantics.
https://json-schema.org/draft/2020-12/json-schema-validation.html#rfc.section.9.4
https://json-schema.org/draft/2020-12/json-schema-validation.html#rfc.section.6.5.3
No word on mixing required and readOnly.
New compatibility option to mark readOnly+required fields as non poin…
New compatibility option to mark readOnly+required fields as non poin…
New compatibility option to mark readOnly+required fields as non poin…
florentchauveau commentedon Jun 3, 2022
I have updated my pull request #605 to create a new configuration in the
compatibilitysection.This way, client code can be generated with the default settings (pointers), but the server can be generated without the pointers.
New compatibility option to mark readOnly+required fields as non poin…
New compatibility option to mark readOnly+required fields as non poin…
New compatibility option to mark readOnly+required fields as non poin…
New compatibility option to mark readOnly+required fields as non poin…
New compatibility option to mark readOnly+required fields as non poin…
New compatibility option to mark readOnly+required fields as non poin…
New compatibility option to mark readOnly+required fields as non poin…
New compatibility option to mark readOnly+required fields as non poin…