Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.

Commit

Permalink
Merge 8bc3112 into cadc93e
Browse files Browse the repository at this point in the history
  • Loading branch information
romamd committed Jan 25, 2019
2 parents cadc93e + 8bc3112 commit 5d5f719
Show file tree
Hide file tree
Showing 19 changed files with 1,089 additions and 1,024 deletions.
2,030 changes: 1,015 additions & 1,015 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 16 additions & 2 deletions src/oas30/oas30MethodConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,13 @@ class Oas30MethodConverter extends Converter {
// $ExpectError sorry, but I don't really know how to fix it and it works as intended
if (header.schema.type === 'array' && header.schema.items == null) header.schema.items = { type: 'string' };
}
if (header.example != null) delete header.example;
if (header.example) {
/**
* Keep 'example' field as extension
* */
header['x-example'] = header.example;
delete header.example;
}
if (header.schema.required != null) delete header.required;
if (header.repeat != null) delete header.repeat;
}
Expand Down Expand Up @@ -320,7 +326,15 @@ class Oas30MethodConverter extends Converter {
if (schema.type === 'array' && schema.items == null) schema.items = { type: 'string' };
delete schema.required;
header.schema = schema;

/**
* Keep 'example' field as extension
* */
if (header.example) {
header['x-example'] = header.example;
}
if (definition.example) {
header['x-example'] = definition.example;
}
helper.removePropertiesFromObject(header, ['example']);
Oas30MethodConverter.exportRequired(value, header);
Oas30RootConverter.exportAnnotations(value, header);
Expand Down
9 changes: 9 additions & 0 deletions src/oas30/oas30ResourceConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ class Oas30ResourceConverter extends Converter {
parameter.description = parameter.schema.description;
delete parameter.schema.description;
}
if (parameter.schema.example) {
/**
* Add 'example' field as extension, because oas doesn't support 'example' field in path params
* Anyway, it is useful for some tools, for example dredd
* @see https://github.com/apiaryio/dredd/issues/540
* @see https://dredd.readthedocs.io/en/latest/how-it-works.html#uri-parameters
* */
parameter['x-example'] = parameter.schema.example;
}
helper.removePropertiesFromObject(parameter, ['example']);
Oas30RootConverter.exportAnnotations(value, parameter);
parameters.push(parameter);
Expand Down
8 changes: 5 additions & 3 deletions test/data/raml10-oas30/source/api-example-lrg-3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,10 @@ types:
type: ServiceSpec
'/{userName}/{serviceName}':
uriParameters:
userName: {}
serviceName: {}
userName:
example: user123
serviceName:
example: order
get:
description: >-
Get the schema of a service(with name serviceName) of a user (with name
Expand Down Expand Up @@ -339,4 +341,4 @@ types:
type: Status
body:
application/json:
type: DataEntry
type: DataEntry
4 changes: 3 additions & 1 deletion test/data/raml10-oas30/source/resource-headers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ version: 1
reviews:
type: array
description: Employee´s reviews
example: ['Great!']
items:
type: string
required: true
names: string
nicknames:
type: string
required: false
age?: integer
example: nick123
age?: integer
5 changes: 4 additions & 1 deletion test/data/raml10-oas30/source/resource-parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version: 1
id:
type: integer
required: false
example: 1
code: string
name:
type: string
Expand All @@ -15,7 +16,9 @@ version: 1
code:
type: string
required: true
example: xyz
/names/{name}:
uriParameters:
name:
description: name
description: name
example: John
1 change: 1 addition & 0 deletions test/data/raml10-oas30/source/resource-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ schemas:
description: Bottle UID
type: string
required: true
example: d7a852d5-9deb-4e4a-a77f-622b3689d787
displayName: bottleUid
get:
displayName: getBottle
Expand Down
1 change: 1 addition & 0 deletions test/data/raml10-oas30/source/resource-simple.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ resourceTypes:
names:
description: names
type: string
example: fake
3 changes: 3 additions & 0 deletions test/data/raml10-oas30/source/resource-traits.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ traits:
application/json:
type: string
headers:
comments:
type: integer
example: 12
reviews: string
age?: integer
responses:
Expand Down
5 changes: 4 additions & 1 deletion test/data/raml10-oas30/source/response-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ types:
body:
application/json:
schema: pet
headers:
Server:
example: Apache
201:
body:
application/json:
Expand All @@ -41,4 +44,4 @@ types:
surname: Doe
second:
name: Jack
surname: Sparrow
surname: Sparrow
3 changes: 2 additions & 1 deletion test/data/raml10-oas30/source/tagAnnotation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ types:
description: ID of pet that needs to be updated
type: integer
format: int64
example: 1
post:
displayName: POST_pet-petId
responses:
Expand All @@ -94,4 +95,4 @@ types:
'400':
description: Invalid tag value
(oas-tags):
- pet
- pet
6 changes: 6 additions & 0 deletions test/data/raml10-oas30/target/api-example-lrg-3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,13 @@ paths:
- in: path
name: userName
required: true
x-example: user123
schema:
type: string
- in: path
name: serviceName
required: true
x-example: order
schema:
type: string
'/service/{userName}/{serviceName}/entry':
Expand Down Expand Up @@ -246,11 +248,13 @@ paths:
- in: path
name: userName
required: true
x-example: user123
schema:
type: string
- in: path
name: serviceName
required: true
x-example: order
schema:
type: string
'/service/{userName}/{serviceName}/entry/{id}':
Expand Down Expand Up @@ -339,11 +343,13 @@ paths:
- in: path
name: userName
required: true
x-example: user123
schema:
type: string
- in: path
name: serviceName
required: true
x-example: order
schema:
type: string
components:
Expand Down
2 changes: 2 additions & 0 deletions test/data/raml10-oas30/target/resource-headers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ paths:
in: header
name: reviews
required: true
x-example: ['Great!']
schema:
type: array
items:
Expand All @@ -22,6 +23,7 @@ paths:
type: string
- in: header
name: nicknames
x-example: nick123
schema:
type: string
- in: header
Expand Down
3 changes: 3 additions & 0 deletions test/data/raml10-oas30/target/resource-parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ paths:
parameters:
- in: path
name: id
x-example: 1
required: true
schema:
type: integer
Expand All @@ -16,6 +17,7 @@ paths:
- in: path
name: code
required: true
x-example: xyz
schema:
type: string
'/names/{name}':
Expand All @@ -24,6 +26,7 @@ paths:
description: name
name: name
required: true
x-example: John
schema:
type: string
components:
Expand Down
1 change: 1 addition & 0 deletions test/data/raml10-oas30/target/resource-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ paths:
description: Bottle UID
in: path
name: bottleUid
x-example: d7a852d5-9deb-4e4a-a77f-622b3689d787
schema:
type: string
/employees:
Expand Down
1 change: 1 addition & 0 deletions test/data/raml10-oas30/target/resource-simple.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ paths:
headers:
names:
description: names
x-example: fake
schema:
type: string
content:
Expand Down
7 changes: 7 additions & 0 deletions test/data/raml10-oas30/target/resource-traits.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ components:
name: nicknames
schema:
type: string
trait_pets_comments:
in: header
name: comments
required: true
x-example: 12
schema:
type: integer
trait_pets_reviews:
in: header
name: reviews
Expand Down
5 changes: 5 additions & 0 deletions test/data/raml10-oas30/target/response-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/pet'
headers:
Server:
x-example: Apache
schema:
type: string
'201':
description: ''
content:
Expand Down
1 change: 1 addition & 0 deletions test/data/raml10-oas30/target/tagAnnotation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ paths:
- description: ID of pet that needs to be updated
in: path
name: petId
x-example: 1
required: true
schema:
type: integer
Expand Down

0 comments on commit 5d5f719

Please sign in to comment.