flowneee / okapi-operation Goto Github PK
View Code? Open in Web Editor NEWProcedural macro for generating OpenAPI operation specification (using okapi)
License: MIT License
Procedural macro for generating OpenAPI operation specification (using okapi)
License: MIT License
It would be nice if we could serve the openapi both as yaml and json. This is commonly done by either using the Accept
header, or by reading a format=[json|yaml]
query parameter.
If there is 2 or more types with same name, they will override each other, when schema generated. For example
handler1.rs
#[derive(JsonSchema)]
struct Request {
name: String
}
handler2.rs
#[derive(JsonSchema)]
struct Request {
id: u64
}
will create only one definition in #/components/schema
, and handlers from both files wil reference same schema.
First potenial fix - enable inlining in https://docs.rs/schemars/latest/schemars/gen/struct.SchemaSettings.html#structfield.inline_subschemas, which will solve most problems (probably everything sxcept recursive types).
Hi, would it be possible to default the operation_id
to the handler method name?
Need to check all public API of this crate against https://rust-lang.github.io/api-guidelines/checklist.html, fixing all issues OR providing explanation for exceptions.
In the following scenario:
axum_integration::Router::new()
.route(
"/subscriptions",
post(openapi_handler!(subscriptions::create_subscription)),
)
.route(
"/subscriptions",
get(openapi_handler!(subscriptions::list_subscriptions)),
)
The latter route
invocation will overwrite the former. This behavior is different from axum, as described here https://docs.rs/axum/latest/axum/struct.Router.html#accepting-multiple-methods
Example:
!10181 โ http -v GET localhost:8081/openapi Accept:application/yaml
GET /openapi HTTP/1.1
Accept: application/yaml
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: localhost:8081
User-Agent: HTTPie/3.2.1
HTTP/1.1 400 Bad Request
content-length: 72
content-type: text/plain; charset=utf-8
date: Wed, 10 May 2023 08:06:34 GMT
Bad Accept header value, should be either 'json', 'yaml', '*/*' or empty
Seems like application/yaml
(nor text/yaml
) works. Both are used as yaml data types. application/json
and text/json
doesn't work either with same error.
Hi, I would like to be able to extract the specification generated by Router::route_openapi_specification
without serving the contract, how can I do it? Could we split route_openapi_specification
in two steps?
Hi, I was wondering if it's possible for a path to infer its documentation
and summary
from its rustdoc, in a similar fashion to how schemars does it: https://graham.cool/schemars/examples/6-doc_comments/
Current name originally was made to refer fact that crate provide macro to generate OpenAPI operation definition using okapi
types.
Why name is not good:
okapi
project (which is false);axum
(and potentially for different frameworks);okapi
to something different (or maybe fork okapi
), because okapi
is designed to support OpenAPI 3.0, while there is 3.1 version which use JSON Schema draft 2020-12 for describing schemas, and as I understand okapi
not planning to support different versions;So I think it would be good to have something neutral, not referring to any specific project or crate, and and general enough to include different instruments for building HTTP API specifications from code.
Currently project consist of 2 crates - main (okapi-operation
) and proc-macro (okapi-operation-macro
). I think it is good idea to split it into multiple crates
-core
: core types and traits (like ToResponses
, ToMediaTypes
) + impls for framework-specific types (like axum::extract::Json) under feature flags (because of orphanage rules)-<framework>
: additional framework-specific things, for example for axum it could be Router replacement;-macro
: proc-macro crate as is + framework-specific features under feature flagsA declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.