-
Notifications
You must be signed in to change notification settings - Fork 15
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: true
not supported
#13
Comments
Thank you for raising this issue. Happy to hear more about the other issues you raised (example gen panics; enum support) Can you provide a minimum OpenAPI spec that uses readonly? It doesn't sound like it'd be too difficult to add support. WorkaroundOne workaround idea until this is implemented: I've seen other OpenAPI specs explicitly create two Schemas in the spec. You could write a pre-processing step for the OpenAPI spec to change it before using libninja. Libninja itself has several examples of these pre-processing steps. Depending on the changes needed, sometimes it's been necessary to operate on the Yaml, other times on the ImplementationHave you thought through what the desired codegen looks like? On first pass, I'm imagining something like this: #[derive(Serialize, Deserialize)
pub struct UserModifiable {
pub name: String
}
#[derive(Serialize, Deserialize)
pub struct UserResponse {
pub created_at: DateTime
#[serde(flatten)]
pub inner: UserModifiable
} Open questions that I see:
If you file a PR, happy to review that directly. |
Thanks for the reply - I'll try the workaround as you suggest, updating the OpenAPI rust struct before generation is an interesting idea. Minimal openapi spec here:
Per spec:
Implementation
|
Sounds good. I'll wait for an update from you on the pre-processing approach.
Thinking through this, I'm wondering if the actual implementation could just be that pre-processing step. It doesn't require modifying codegen, which is both simpler, and it gets implemented for free for the other languages libninja supports. |
👋🏽
First of all, thanks for writing this library - I'm looking for an openapi client generator for internal APIs and I tried 3 other options and this was the only tool that produced code that compiles without issues. I hit some random issues (eg example generation panics) but I like the code this produces and it has most of the features I'd like (enums would be the next on my wishlist ;-)).
The main blocker I found is not respecting
readOnly: true
. I have a schema that hasreadOnly: true
, meaning that the property should only be in responses but not in requests. In my case, I have a POST api to create a resource and a GET api to load the resource, the schema is the same but certain properties (egcreated_at
) are marked as readOnly. Libninja treats that as a required field even in requests.Happy to take a look at implementing this if this is something you'd be open to adding / reviewing
The text was updated successfully, but these errors were encountered: