-
-
Notifications
You must be signed in to change notification settings - Fork 894
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Generate models for all JSON media types
As highlighted in #1168, we have some cases where JSON-compatible media types aren't having their respective models generated, as we previously only looked for `application/json`. To resolve this, we can make sure that any media types that are compatible with JSON (via our utility method) can have their types generated. This is a fix for #1168, which could also be deemed a feature. However, as this has broken in the upgrade from v1.12.x to v1.13.x, this is being treated as a feature. Closes #1168.
- Loading branch information
1 parent
f20166f
commit e90f06d
Showing
5 changed files
with
292 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package issue1168 | ||
|
||
//go:generate go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen --config=server.config.yaml spec.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package: issue1168 | ||
output: | ||
api.gen.go | ||
generate: | ||
models: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
--- | ||
# Copyright 2023 Coros, Corp. All Rights Reserved. | ||
# | ||
# Apache 2.0 Licensed; the portion included from | ||
# https://github.com/zalando/problem/ is MIT licensed | ||
# | ||
openapi: 3.0.3 | ||
info: | ||
version: 1.0.0 | ||
title: Test | ||
description: Provides access to things | ||
license: | ||
name: Apache License 2.0 | ||
url: http://www.example.com/XXX | ||
|
||
servers: | ||
- url: https://www.example.com/api | ||
description: Production environment | ||
|
||
paths: | ||
/v1/test: | ||
get: | ||
summary: Get it | ||
responses: | ||
'200': | ||
description: Successful response | ||
content: | ||
text/plain: | ||
type: string | ||
'400': | ||
$ref: '#/components/responses/Misc400Error' | ||
'404': | ||
$ref: '#/components/responses/Misc404Error' | ||
|
||
components: | ||
responses: | ||
Misc400Error: | ||
description: Bad request | ||
content: | ||
application/problem+json: | ||
schema: | ||
$ref: '#/components/schemas/ProblemDetails' | ||
Misc404Error: | ||
description: Not found | ||
content: | ||
application/problem+json: | ||
schema: | ||
$ref: '#/components/schemas/ProblemDetails' | ||
|
||
schemas: | ||
# Fetched from https://opensource.zalando.com/problem/schema.yaml | ||
# and slightly modified. | ||
# Part of https://github.com/zalando/problem/; MIT License | ||
ProblemDetails: | ||
type: object | ||
additionalProperties: true | ||
properties: | ||
type: | ||
type: string | ||
format: uri | ||
description: >- | ||
An absolute URI that identifies the problem type. When dereferenced, | ||
it SHOULD provide human-readable documentation for the problem type | ||
(e.g., using HTML). | ||
default: 'about:blank' | ||
example: 'https://zalando.github.io/problem/constraint-violation' | ||
title: | ||
type: string | ||
description: >- | ||
A short, summary of the problem type. Written in english and readable | ||
for engineers (usually not suited for non technical stakeholders and | ||
not localized); example: Service Unavailable | ||
status: | ||
type: integer | ||
format: int32 | ||
description: >- | ||
The HTTP status code generated by the origin server for this occurrence | ||
of the problem. | ||
minimum: 100 | ||
maximum: 600 | ||
exclusiveMaximum: true | ||
example: 503 | ||
detail: | ||
type: string | ||
description: >- | ||
A human readable explanation specific to this occurrence of the | ||
problem. | ||
example: Connection to database timed out | ||
instance: | ||
type: string | ||
format: uri | ||
description: >- | ||
An absolute URI that identifies the specific occurrence of the problem. | ||
It may or may not yield further information if dereferenced. | ||
# </MIT License> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters