Skip to content

Commit 912141a

Browse files
authored
Backwards compatibility flag for alias handling (#3239)
* add backwards compatibility --transparent-aliases flag Signed-off-by: cce <51567+cce@users.noreply.github.com> * update as per CR feedback Signed-off-by: cce <51567+cce@users.noreply.github.com> --------- Signed-off-by: cce <51567+cce@users.noreply.github.com>
1 parent 3375f28 commit 912141a

5 files changed

Lines changed: 298 additions & 0 deletions

File tree

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
{
2+
"consumes": [
3+
"application/json"
4+
],
5+
"produces": [
6+
"application/json"
7+
],
8+
"schemes": [
9+
"https"
10+
],
11+
"swagger": "2.0",
12+
"info": {
13+
"description": "the purpose of this application is to provide an application\nthat is using plain go code to define an API",
14+
"title": "API.",
15+
"version": "0.0.1"
16+
},
17+
"host": "localhost",
18+
"paths": {
19+
"/admin/bookings/": {
20+
"get": {
21+
"consumes": [
22+
"application/json"
23+
],
24+
"produces": [
25+
"application/json"
26+
],
27+
"schemes": [
28+
"http",
29+
"https"
30+
],
31+
"tags": [
32+
"booking"
33+
],
34+
"summary": "Bookings lists all the appointments that have been made on the site.",
35+
"operationId": "Bookings",
36+
"deprecated": true,
37+
"responses": {
38+
"200": {
39+
"$ref": "#/responses/BookingResponse"
40+
}
41+
}
42+
}
43+
}
44+
},
45+
"definitions": {
46+
"Booking": {
47+
"description": "A Booking in the system",
48+
"type": "object",
49+
"required": [
50+
"id",
51+
"Subject"
52+
],
53+
"properties": {
54+
"Subject": {
55+
"description": "Subject the subject of this booking",
56+
"type": "string"
57+
},
58+
"id": {
59+
"description": "ID the id of the booking",
60+
"type": "integer",
61+
"format": "int64",
62+
"x-go-name": "ID",
63+
"readOnly": true
64+
}
65+
},
66+
"x-go-package": "github.com/go-swagger/scan-repo-boundary/makeplans"
67+
},
68+
"DateRange": {
69+
"description": "DateRange represents a scheduled appointments time\nDateRange should be in definitions since it's being used in a response",
70+
"type": "object",
71+
"properties": {
72+
"end": {
73+
"type": "string",
74+
"x-go-name": "End"
75+
},
76+
"start": {
77+
"type": "string",
78+
"x-go-name": "Start"
79+
}
80+
},
81+
"x-go-package": "github.com/go-swagger/go-swagger/fixtures/goparsing/spec"
82+
},
83+
"User": {
84+
"type": "object",
85+
"properties": {
86+
"name": {
87+
"type": "string",
88+
"x-go-name": "Name"
89+
}
90+
},
91+
"x-go-package": "github.com/go-swagger/go-swagger/fixtures/goparsing/spec"
92+
}
93+
},
94+
"responses": {
95+
"BookingResponse": {
96+
"description": "BookingResponse represents a scheduled appointment",
97+
"schema": {
98+
"type": "object",
99+
"properties": {
100+
"booking": {
101+
"$ref": "#/definitions/Booking"
102+
},
103+
"customer": {
104+
"$ref": "#/definitions/User"
105+
},
106+
"dates": {
107+
"$ref": "#/definitions/DateRange"
108+
},
109+
"map": {
110+
"type": "object",
111+
"additionalProperties": {
112+
"type": "string"
113+
},
114+
"x-go-name": "Map",
115+
"example": {
116+
"key": "value"
117+
}
118+
},
119+
"slice": {
120+
"type": "array",
121+
"items": {
122+
"type": "integer",
123+
"format": "int64"
124+
},
125+
"x-go-name": "Slice",
126+
"example": [
127+
1,
128+
2
129+
]
130+
}
131+
}
132+
}
133+
}
134+
}
135+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
consumes:
2+
- application/json
3+
definitions:
4+
Booking:
5+
description: A Booking in the system
6+
properties:
7+
Subject:
8+
description: Subject the subject of this booking
9+
type: string
10+
id:
11+
description: ID the id of the booking
12+
format: int64
13+
readOnly: true
14+
type: integer
15+
x-go-name: ID
16+
required:
17+
- id
18+
- Subject
19+
type: object
20+
x-go-package: github.com/go-swagger/scan-repo-boundary/makeplans
21+
DateRange:
22+
description: |-
23+
DateRange represents a scheduled appointments time
24+
DateRange should be in definitions since it's being used in a response
25+
properties:
26+
end:
27+
type: string
28+
x-go-name: End
29+
start:
30+
type: string
31+
x-go-name: Start
32+
type: object
33+
x-go-package: github.com/go-swagger/go-swagger/fixtures/goparsing/spec
34+
User:
35+
properties:
36+
name:
37+
type: string
38+
x-go-name: Name
39+
type: object
40+
x-go-package: github.com/go-swagger/go-swagger/fixtures/goparsing/spec
41+
host: localhost
42+
info:
43+
description: |-
44+
the purpose of this application is to provide an application
45+
that is using plain go code to define an API
46+
title: API.
47+
version: 0.0.1
48+
paths:
49+
/admin/bookings/:
50+
get:
51+
consumes:
52+
- application/json
53+
deprecated: true
54+
operationId: Bookings
55+
produces:
56+
- application/json
57+
responses:
58+
"200":
59+
$ref: '#/responses/BookingResponse'
60+
schemes:
61+
- http
62+
- https
63+
summary: Bookings lists all the appointments that have been made on the site.
64+
tags:
65+
- booking
66+
produces:
67+
- application/json
68+
responses:
69+
BookingResponse:
70+
description: BookingResponse represents a scheduled appointment
71+
schema:
72+
properties:
73+
booking:
74+
$ref: '#/definitions/Booking'
75+
customer:
76+
$ref: '#/definitions/User'
77+
dates:
78+
$ref: '#/definitions/DateRange'
79+
map:
80+
additionalProperties:
81+
type: string
82+
example:
83+
key: value
84+
type: object
85+
x-go-name: Map
86+
slice:
87+
example:
88+
- 1
89+
- 2
90+
items:
91+
format: int64
92+
type: integer
93+
type: array
94+
x-go-name: Slice
95+
type: object
96+
schemes:
97+
- https
98+
swagger: "2.0"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package transparentalias provides fixtures to exercise transparent alias handling.
2+
package transparentalias
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package transparentalias
2+
3+
// TransparentPayload is the canonical struct referenced by aliases in tests.
4+
//
5+
// swagger:model TransparentPayload
6+
type TransparentPayload struct {
7+
// ID of the payload.
8+
//
9+
// required: true
10+
ID int64 `json:"id"`
11+
12+
// Name of the payload.
13+
Name string `json:"name"`
14+
}
15+
16+
// TransparentPayloadAlias is an exported alias to TransparentPayload.
17+
type TransparentPayloadAlias = TransparentPayload
18+
19+
// QueryValue is the base type used for aliasing query parameters.
20+
type QueryValue string
21+
22+
// QueryValueAlias is an exported alias to QueryValue.
23+
type QueryValueAlias = QueryValue
24+
25+
type transparentAliasParams struct {
26+
// AliasBody exercises alias handling for body parameters.
27+
//
28+
// in: body
29+
// required: true
30+
AliasBody TransparentPayloadAlias `json:"aliasBody"`
31+
32+
// AliasQuery exercises alias handling for non-body parameters.
33+
//
34+
// in: query
35+
AliasQuery QueryValueAlias `json:"aliasQuery"`
36+
}
37+
38+
// TransparentAliasParams is an exported alias annotated as swagger parameters.
39+
//
40+
// swagger:parameters transparentAlias
41+
type TransparentAliasParams = transparentAliasParams
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package transparentalias
2+
3+
// ResponseEnvelope is the canonical struct referenced by aliases in responses.
4+
type ResponseEnvelope struct {
5+
// Payload uses an alias that should resolve transparently.
6+
Payload TransparentPayloadAlias `json:"payload"`
7+
}
8+
9+
// ResponseEnvelopeAlias is an exported alias to ResponseEnvelope.
10+
type ResponseEnvelopeAlias = ResponseEnvelope
11+
12+
type transparentAliasResponse struct {
13+
// Body exercises alias handling for response bodies.
14+
//
15+
// in: body
16+
Body ResponseEnvelopeAlias `json:"body"`
17+
}
18+
19+
// TransparentAliasResponse is an exported alias annotated as swagger response.
20+
//
21+
// swagger:response transparentAliasResponse
22+
type TransparentAliasResponse = transparentAliasResponse

0 commit comments

Comments
 (0)