ergo / pyramid_apispec

Pyramid plugin for openapi spec generation (using ApiSpec)
BSD 3-Clause "New" or "Revised" License
23 stars 10 forks source link

Overwriting paths in the spec #12

Closed christian-heusel closed 5 years ago

christian-heusel commented 5 years ago

Hey there! :blush: I wondered whether it would be possible to overwrite the paths that are currently taken from the decorator to something self-defined..

My problem is that my path is path='/api/exercises/{exercise_id:\d+}/{user_id:(\d+)+\/?}' but that should be kinda internal and I would like to overwrite this with path='/api/exercises/{exercise_id}/{user_id}' so I do not need to show my regex matches to the API user.

From the OpenAPI 2.0 standard:

paths:
  /users: <-- this 
    get:
      summary: Returns a list of users.

Currently this does not seem to be possible, atleast not from what I have tried... :smile: I would therefore suggest adding interpretion for the parameter path like this:

"""
---
path: 
  /api/exercises/{exercise_id}/{user_id}:
     get:
      tags:
        - "My API"
      summary: "return an exercise for given student"
      description: ""
      operationId: "exercise_student_get"
      produces:
        - "application/json"
      responses:
        200:
          description: successfull return of the exercise
          schema:
            $ref: "#/definitions/ExerciseStudent"
"""

Would that be possible? All the best Chris

ergo commented 5 years ago

Hey @TheEbolaDoc,

I think when you do my_spec = spec.to_dict() you can easily alter the spec dictionary any way you want. If you want add interpretation for docstring, that is handled directly by apispec package if I understood correctly what you want.