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
Define part of a request schema with a raw json schema #554
Comments
Hi @lud-wj please see this example An option is to do something like: alias OpenApiSpex.{Operation, Reference}
@index_operation struct(Operation, Jason.decode!(Application.compile_env(:my_app, :index_operation)))
def index_operation() do
%Operation{
tags: ["users"],
summary: "List users",
description: "List all useres",
operationId: "UserController.index",
responses: %{
200 => response("User List Response", "application/json", Schemas.UsersResponse),
422 => %Reference{"$ref": "#/components/responses/unprocessable_entity"}
}
}
end |
Hello, thanks but I do not understand, you do not use the |
@lud-wj The module attribute is not automatically registered. I put it there assuming you're already doing something similar for "should comply to a JSON schema that is generated at compile time". |
I do something similar indeed, but that schema is only the request body schema. I am not sure I can have a full operation as json, because the request body definition is a tuple:
Sure, I can transform the json data to get an operation struct in the end, but there will not be a I feel like |
I can't find a way to load a schema from JSON. Have you considered having any such JSON schemas in a complete OpenAPI spec file which only defines schemas and load it using Also might be worth looking what OperationBuilder and RequestBody to overcome the tuple obstacle. |
Well we want to use the library as usual, except for this route, so I do not feel like having everything in a normalized map. And I guess the builder will have the same error as above. Nevermind, I'll have to make a raw-json-to-OpenApiSpex.Schema transformer. Should be quick. Might as well open a PR with that. |
Hello,
For some route, I accept a body where one of the properties should comply to a JSON schema that is generated at compile time and will change over time. Is there a way to use a raw JSON string or a raw map as a schema in the
operation
call?I have this error:
Is there a way to achieve that?
Thanks!
The text was updated successfully, but these errors were encountered: