question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[REQ] OAS 3.0 support of readOnly/writeOnly modeling

See original GitHub issue

Is your feature request related to a problem? Please describe.

Yes, missing support for OAS 3.0 feature of readOnly and writeOnly properties within a model.

Discussion came up on Slack, and I’m documenting it here since we need to implement this for full OAS 3.0 support.

Describe the solution you’d like

Provide a writeOnlyVars to match other vars in our codegen model. Support differentiation between request models and response models.

Describe alternatives you’ve considered

Early discussions about writeOnly on OAI suggest domain modeling around usage of allOf. See OAI/OpenAPI-Specification/issues/425.

Additional context

OAS 3.x Schema Object supports two properties, readOnly and writeOnly. These properties are defined as:

Field Name Type Description
readOnly boolean 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. Default value is false.
writeOnly boolean Relevant only for Schema "properties" definitions. Declares the property as “write only”. Therefore, it MAY be sent as part of a request but SHOULD NOT be sent as part of the response. If the property is marked as writeOnly being true and is in the required list, the required will take effect on the request only. A property MUST NOT be marked as both readOnly and writeOnly being true. Default value is false.

We should validate that a property is not both readOnly=true and writeOnly=true. This validation should be excluded from strict spec skipping as having a property both readOnly and writeOnly should be a logical error with undefined behavior.

The use of SHOULD NOT in the spec is defined via rfc2119:

SHOULD NOT This phrase, or the phrase “NOT RECOMMENDED” mean that there may exist valid reasons in particular circumstances when the particular behavior is acceptable or even useful, but the full implications should be understood and the case carefully weighed before implementing any behavior described with this label.

So, we’re not technically out of compliance with the spec in relation to readOnly and writeOnly since our use case to support OpenAPI 2.0 and OpenAPI 3.0 functionality in the same generator + template combinations could be considered a “particular circumstance”. However, the we are out of compliance with the clause regarding required because this makes the property required only in a request or response structure, and not both.

My proposal is to do multiple passes on models defined in the OpenAPI result object and sort these into an array of “RequestModels” and an array of “ResponseModels”, leaving our current “models” collection as a raw collection for backward compatibility. This would allow us to have the same schema definition defined appropriately (according to the specification), without hacky workarounds like adding arbitrary prefixes or suffixes to differentiate.

We may be tempted to suggest that users split their schemas, similar to the recommendation linked above (OAI/OpenAPI-Specification/issues/425), but this will only address the issue for those users who own/manage their specifications. To allow code generation from external systems which follow OpenAPI 3.0 specification, we’d need to support this use case.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:33
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

11reactions
last-partizancommented, Sep 21, 2020

Is there any roadmap for this issue?

I’m using typescript-axios generator and it generates invalid code, which requires read-only params for request.

3reactions
MLeipzigercommented, Aug 17, 2021

Is there any update on this issue? As mentioned by @last-partizan this generates invalid code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

OpenAPI Specification - Version 3.0.3 - Swagger
Tooling which supports OAS 3.0 SHOULD be compatible with all OAS 3.0. ... contains a required openapi field which designates the semantic version...
Read more >
OpenAPI Specification v3.1.0 | Introduction, Definitions, & More
The OpenAPI Specification (OAS) defines a standard, programming language-agnostic interface description for HTTP APIs.
Read more >
Open API 3.0 support in Rational Software Architect Designer ...
1, support for modeling and generation of OpenAPI 3.0 specification based Representational State Transfer (REST) web services is provided. Palette tools, ...
Read more >
Open API Specification 3.0 Support - Akana Documentation
Using the JSON Text Editor; Displaying multiple examples in your OAS 3.0 API documentation. JSON Schema Editor: Overview; Adding and editing model objects...
Read more >
OpenAPI 3.0 Domain Example | SwaggerHub Documentation
Below is an example of an OpenAPI 3.0 domain definition ... OpenAPI version identifier - required for OpenAPI 3.0 domains openapi: 3.0.0 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found