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

Add macros for components #12

Merged
merged 9 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,48 @@ optional_fields["basePath"] = ENV["BASEPATH"]
openApi = OpenAPI("3.0", info, optional_fields=optional_fields)
```

### Components

[Components](https://swagger.io/docs/specification/v3_0/components/) are supported by additional macros.

- `@swagger_schemas`
- `@swagger_parameters`
- `@swagger_requestBodies`
- `@swagger_responses`
- `@swagger_headers`
- `@swagger_examples`
- `@swagger_links`
- `@swagger_callbacks`

These can be used anywhere in the code. The following example declares a `User` schema which can be [referenced](https://swagger.io/docs/specification/v3_0/using-ref/).

```julia
using JSON
using SwaggerMarkdown

@swagger_schemas """
User:
properties:
id:
type: integer
name:
type: string
"""
```

The schema can then be used to describe e.g. the response of an endpoint.

```julia
@swagger """
/user:
get:
description: Get a user
responses:
'200':
description: Successful retrieval of a user
schema:
\$ref: "#/components/schemas/User"
"""
```

Please note the `\` in front of `$ref` for escaping the `$` which is normally used for string interpolation.
Loading
Loading