Code Monkey home page Code Monkey logo

okapi-operation's People

Contributors

flowneee avatar grigoriydmitriev avatar josiahbull avatar kryvashek avatar slinkydeveloper avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

okapi-operation's Issues

Serve both as YAML and as JSON

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.

Types with same name overrides schemas in components

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).

`Accept` is not working

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.

Rename crate

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:

  • Some people might think that this crate related to okapi project (which is false);
  • Almost immediately was added spec builder, implementations and integrations for axum (and potentially for different frameworks);
  • There is possibility that this crate will move from 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;
  • Name is ugly)

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.

Split crate

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 flags
  • top-level crate: gather and expose all other crates with framework-specific feature under feature flags

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.