-
-
Notifications
You must be signed in to change notification settings - Fork 92
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
Feature: Convert $PodeContext.server.routes to Swagger/OpenAPI #218
Comments
I've not had much experience with Swagger/OpenAPI before, so I'll have to investigate properly to see if's possible. From an initial look it appears as though it should just be a case of generating a YAML definition from the routes 🤔 I'll keep digging when I get chance to. |
I am on it as well, and will keep you informed. In Swagger you can use JSON, that is what i normally do. |
First commit has basic support for OpenAPI and Swagger. You can enable just OpenAPI, or enable Swagger with it: Enable-PodeOpenApiRoute -Title 'OpenAPI Example' -Filter '/api/'
Enable-PodeSwaggerRoute OpenAPI definition by default can be found at Going to tackle Responses next. |
At present, this is a simple example of setting response codes: Add-PodeRoute -Method Get -Path "/api/resources" -ScriptBlock {
Set-PodeResponseStatus -Code 200
} -PassThru |
Set-PodeOpenApiRouteMetaData -Summary 'A cool summary' -Tags 'Resources' -PassThru |
Add-PodeOpenApiRouteResponse -StatusCode 200 -PassThru |
Add-PodeOpenApiRouteResponse -StatusCode 404 and this is a more complicated example for request path parameters, and response schema: Add-PodeRoute -Method Get -Path '/api/users/:userId' -ScriptBlock {
param($e)
Write-PodeJsonResponse -Value @{ Name = 'Rick'; UserId = $e.Parameters['userId'] }
} -PassThru |
Set-PodeOpenApiRouteMetaData -Summary 'A cool summary' -Tags 'Users' -PassThru |
Set-PodeOpenApiRouteRequest -Parameters @(
New-PodeOpenApiRouteRequestParameter -Integer -Name 'userId' -In Path -Required
) -PassThru |
Add-PodeOpenApiRouteResponse -StatusCode 200 -Description 'A list of users' -Schemas @(
New-PodeOpenApiSchema -Object -ContentType 'application/json' -Properties @(
New-PodeOpenApiSchemaProperty -Name 'Name' -String
New-PodeOpenApiSchemaProperty -Name 'UserId' -Integer
)
) |
Things left to look at:
|
👀 |
Would these help in anyway ? https://github.com/beatcracker/POSH-swagger-codegen https://github.com/Azure/autorest perhaps checking the results or getting ideas from |
AutoRest I'm aware of, was going to use it during testing 😃 They're obviously a little different, as they're consuming an OpenAPI definition; building one is a whole other nightmare, haha 😂 I currently have pretty much all of the basics working. I'm just working on a refactor to make RequestBody/Response schemas simpler - then onto testing! |
Last commit is a big refactor on simplifying setting RequestBody and Response schemas. Next is to tackle Component Schemas, so we can reference generic schemas. |
Added in ReDoc support on top of the Swagger support |
Nice. Redoc rocks. |
Do you have any idea how to convert all the routes to Swagger?
The text was updated successfully, but these errors were encountered: