Skip to content
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

Data Validation not taking place with uiversion 3 and openAPI 3.0.1 #357

Closed
caffeinatedMike opened this issue Jan 22, 2020 · 2 comments · Fixed by #504
Closed

Data Validation not taking place with uiversion 3 and openAPI 3.0.1 #357

caffeinatedMike opened this issue Jan 22, 2020 · 2 comments · Fixed by #504

Comments

@caffeinatedMike
Copy link

I'm working on simultaneously refactoring and converting an old project from Swagger 2 to the new openAPI 3. The swagger doc renders fine, but if I attempt to make any requests with intentionally malformed content the validation errors are no longer thrown and all requests seems to successfully go through. It seems with this module's openAPI 3 implementation nothing is validated against the swagger spec.

Below is a bare-bones version of my code

from flasgger import Swagger, LazyString, LazyJSONEncoder
from flask import Flask, url_for
from flask_restful import Api, Resource

app = Flask(__name__)
api = Api(app)
app.json_encoder = LazyJSONEncoder
app.config['SWAGGER'] = {
    'title': 'RencomAPI',
    'uiversion': 3,
    'openapi': '3.0.1',
    'favicon': LazyString(lambda: url_for('static', filename='logo.png')),
    'swagger_ui_css': LazyString(lambda: url_for('static', filename='swagger-ui.css')),
    'specs_route': '/'
}

swagger = Swagger(app, template_file='static/Swagger.yml', parse=True)

class NewProduct(Resource):
    # Create a new product
    def post(self):
        pass

api.add_resource(NewProduct, '/product')

if __name__ == "__main__":
    app.run(debug=True)

And my Swagger spec file

openapi: 3.0.1
info:
  title: Proof-of-Concept
servers:
- url: http://127.0.0.1:5000/
- url: https://127.0.0.1:5000/
paths:
  /product:
    post:
      tags:
      - Product
      summary: Add a new product
      description: Create new product listings.
      operationId: addProduct
      requestBody:
        description: Product object to be added to your catalog
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RawItem'
        required: true
      responses:
        200:
          description: Product created
          content: {}
        405:
          description: Invalid input
          content: {}
        501:
          description: Not Yet Implemented
          content: {}
      x-codegen-request-body-name: body
components:
  schemas:
    RawItem:
      type: object
      required:
      - upc
      properties:
        id:
          type: integer
          format: int32
        itemNumber:
          type: string
          description: Your unique code pertaining only to this product
          example: 1006-10
        upc:
          type: integer
          description: Universal Product Code
          format: int32
@caffeinatedMike
Copy link
Author

@billyrrr @rochacbruno Any idea if this is actually a bug or am I doing something wrong?

@Lounarok
Copy link
Contributor

Lounarok commented Nov 8, 2021

This should be a bug. It seems validation only takes schemas in definitions into account.
I'm trying to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants