Coder Social home page Coder Social logo

Comments (8)

ahopkins avatar ahopkins commented on July 21, 2024 1

Yup, that makes sense. That is a feature we need to add still: https://github.com/sanic-org/sanic-ext/blob/main/sanic_ext/extensions/openapi/openapi.py#L230

Hopefully we can squeeze this one into the upcoming release.

from sanic-ext.

ahopkins avatar ahopkins commented on July 21, 2024 1

Documentation

from sanic-ext.

ahopkins avatar ahopkins commented on July 21, 2024

Odd. I am curious to know if it is that we are generating invalid OAS, or is an issue with the client. Do you know that this works in other Swagger installations?

from sanic-ext.

ahopkins avatar ahopkins commented on July 21, 2024

I don't think this is related, but there is an open PR re: that decorator: #21

from sanic-ext.

dacasals avatar dacasals commented on July 21, 2024

I found the problem and it is specifically related with the Authorization header.
The thing is in this case, as mentioned here
"Note: Header parameters named Accept, Content-Type and Authorization are not allowed. To describe these headers, use the corresponding OpenAPI keywords"

So for the Authorization header i think the sanic-ext needs to implement the specification described here.

So the ir no problem with the openapi.parameter for others headers except headers mentioned above.

In the case of Authorization, we need to generate something like this:

{"openapi": "3.0.0",
  "info": {
    "title": "API",
    "version": "1.0.0",
    "contact": {
      
    }
  },
  "components":
  { "securitySchemes":{
    "BearerAuth":{
      "type": "http",
      "scheme": "bearer"
    }
  }
    
  },

  "paths": {
    "/": {
      "get": {
        "operationId": "get_route_name",
        "summary": "Hello World",
        "security": [{"BearerAuth":[]}],
        "responses": {
          "default": {
            "description": "OK"
          }
        }
      }
    }
  },
  "tags": [
    
  ],
  "servers": [
    
  ]
}

from sanic-ext.

dacasals avatar dacasals commented on July 21, 2024

Thanks, in the mean time if someone get stuck with this and found this thread, you could do a ugly hack like this:

# You must  add  security schemas to the singleton Builder of the specification..

app = Sanic("app", log_config=define_logging_config(LOGGING_CONFIG))
....
# Modify Singleton builder to add security schemes, ex: add a bearerAuth schema for bearer tokens :
SpecificationBuilder().add_component(
    "securitySchemes", "BearerAuth", {"type": "http", "scheme": "bearer"}
...
Extend(app)
from sanic_ext import openapi

# This hack is to override default behavior of sanic_ext openapi allow **secured** decorator. 
def secured(*args, **kwargs):
   #  raise NotImplementedError(
   #    "SecuritySchemas are not yet implemented in sanic-openapi 0.6.3, "
   #     "hopefully they should be ready for the next release."
   # )
    def inner(func):
        OperationStore()[func].secured(*args, **kwargs)
        return func

    return inner


openapi.secured = secured
# Finally annotate your secure route with:

@blueprint.route("/some_route", methods=["POST"])
@openapi.secured("BearerAuth")

Tested on sanic and sanic_ext 21.9.3

from sanic-ext.

ahopkins avatar ahopkins commented on July 21, 2024

Working on this

#32

from sanic-ext.

ahopkins avatar ahopkins commented on July 21, 2024

This is now released in v21.12.2 without @dacasals nice hack.

from sanic-ext.

Related Issues (20)

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.