Giter Site home page Giter Site logo

Comments (7)

kibertoad avatar kibertoad commented on July 28, 2024

What do you have baseUrl for in this case? Swagger spec explicitly says: All API endpoints are relative to the base URL, so if your spec is structured otherwise, you are in a violation of spec.

from openapi-validator-middleware.

kibertoad avatar kibertoad commented on July 28, 2024

@hpl002 Wait, it should be the other way around. You can add api/ as baseUrl in your spec and it will be concatted automatically when doing the matching.

Would be easier to understand situation if you shared (potentially with scrambled names) relevant fragments of your spec.

from openapi-validator-middleware.

hpl002 avatar hpl002 commented on July 28, 2024

Thanks for getting back to me.

Here is a derivative of your pets.yaml spec

openapi: 3.0.0
servers:
  - url: "https://api.paymentsos.com/"
info:
  title: PaymentsOS API
  version: 1.0.0
x-flow-proxies:
  accounts:
    target: http://localhost:3020
paths:
  /accounts:
    x-flow-proxy: accounts  
    get:
      summary: get all pets

      tags:
        - pets
      operationId: listPets
      responses:
        "200":
          description: list of pets
          headers:
            x-zooz-request-id:
              description: request id
              schema:
                type: string
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/pets"

components:
  schemas:
    error_model:
      required:
        - description
        - category
      properties:
        category:
          type: string
          description: Error code.
        description:
          type: string
          description: Error message for the developer.
        more_info:
          type: string
          description: "More info about the error, can include link to the documentation."
    pet:
      description: pet
      type: object
      oneOf:
        - $ref: "#/components/schemas/dog_object"
        - $ref: "#/components/schemas/cat_object"
    pet2:
      description: pet
      type: object
      oneOf:
        - $ref: "#/components/schemas/dog_object2"
        - $ref: "#/components/schemas/cat_object"
    pets:
      type: array
      items:
        $ref: "#/components/schemas/pet"
    pet-discriminator-on-child:
      description: pet
      type: object
      required:
        - pet
      properties:
        pet:
          $ref: "#/components/schemas/pet-discriminator"
    pet-discriminator:
      description: pet
      type: object
      oneOf:
        - $ref: "#/components/schemas/dog_object"
        - $ref: "#/components/schemas/cat_object"
      discriminator:
        propertyName: type
    pet-discriminator-multiple:
      description: pet
      type: object
      oneOf:
        - $ref: "#/components/schemas/dog_multiple"
        - $ref: "#/components/schemas/cat_object"
      discriminator:
        propertyName: type
      properties:
        name:
          type: string
      required:
        - name
    pet-discriminator-mapping:
      description: pet
      type: object
      oneOf:
        - $ref: "#/components/schemas/dog_multiple"
        - $ref: "#/components/schemas/cat_object"
      discriminator:
        propertyName: type
        mapping:
          mapped_dog: "#/components/schemas/dog_multiple"
          mapped_cat: "#/components/schemas/cat_object"
      properties:
        name:
          type: string
      required:
        - name
    dog_object:
      type: object
      required:
        - bark
      properties:
        bark:
          type: string
    dog_object2:
      type: object
      required:
        - bark
      properties:
        bark:
          type: string
          enum:
            - foo
            - bar
    dog_multiple:
      type: object
      required:
        - dog_age
      discriminator:
        propertyName: model
      oneOf:
        - $ref: "#/components/schemas/small_dog"
        - $ref: "#/components/schemas/big_dog"
      properties:
        dog_age:
          type: string
    cat_object:
      type: object
      required:
        - fur
      properties:
        fur:
          type: string
          pattern: '^\d+$'

    small_dog:
      type: object
      required:
        - max_length
      properties:
        max_length:
          type: string
    big_dog:
      type: object
      required:
        - min_length
      properties:
        min_length:
          type: string
    medium_dog:
      type: object
      required:
        - min_length
        - max_length
      additionalProperties: false
      properties:
        max_length:
          type: string
        min_length:
          type: string

if have to set basepath for use with my other middleware. This creates a conflict when calling
const methodSchema = schemaEndpointResolver.getMethodSchema(schemas, path, method) paths in schemas and path do not align, thus resulting in undefined and no validation.

Edit:
Endpoints in schemas object are not prefixed with basepath
Screenshot 2020-05-12 at 21 18 52

from openapi-validator-middleware.

kibertoad avatar kibertoad commented on July 28, 2024

And when you change server to

servers:
  - url: "https://api.paymentsos.com/api"

that doesn't help?

from openapi-validator-middleware.

hpl002 avatar hpl002 commented on July 28, 2024

No,still same result.

Did however bypass this by just forecefully setting the baseurl to nothing before sending it in. Works, but not ideal..

 return async (req, res, next) => {
   const currBase = req.baseUrl;
   req.baseUrl = "";
   inputValidation.init(gatewayConfiguration.configPath);
   inputValidation.validate(req, res, next);
   req.baseUrl = currBase;
   next();
 };
}

from openapi-validator-middleware.

hpl002 avatar hpl002 commented on July 28, 2024

Feel free to close the issue is you're not planning to address it further. Forcefully setting the baseUrl works..

from openapi-validator-middleware.

kibertoad avatar kibertoad commented on July 28, 2024

no-no, I still need to look into it

from openapi-validator-middleware.

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.