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

airtasker#1367 Implementation for SchemaProps #1376

Merged
merged 13 commits into from
May 3, 2021
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
146 changes: 146 additions & 0 deletions lib/src/generators/openapi2/__snapshots__/openapi2.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,152 @@ exports[`OpenAPI 2 generator responses endpoint specific and default responses 1
}"
`;

exports[`OpenAPI 2 generator schemaprops contract with schemaprops parses correctly to an openapi specification 1`] = `
"{
\\"swagger\\": \\"2.0\\",
\\"info\\": {
\\"title\\": \\"contract\\",
\\"version\\": \\"0.0.0\\"
},
\\"consumes\\": [
\\"application/json\\"
],
\\"produces\\": [
\\"application/json\\"
],
\\"paths\\": {
\\"/users\\": {
\\"get\\": {
\\"operationId\\": \\"EndpointWithSchemaPropsOnHeaders\\",
\\"parameters\\": [
{
\\"name\\": \\"status\\",
\\"in\\": \\"header\\",
\\"description\\": \\"property-schemaprop description for string\\",
\\"required\\": true,
\\"type\\": \\"string\\",
\\"minLength\\": 12,
\\"maxLength\\": 20,
\\"pattern\\": \\"^[0-9a-z_]+$\\"
},
{
\\"name\\": \\"size\\",
\\"in\\": \\"header\\",
\\"description\\": \\"property-schemaprop description for integer\\",
\\"required\\": true,
\\"type\\": \\"integer\\",
\\"format\\": \\"int32\\",
\\"minimum\\": 1,
\\"default\\": 42
}
],
\\"responses\\": {
\\"200\\": {
\\"description\\": \\"200 response\\",
\\"schema\\": {
\\"type\\": \\"array\\",
\\"items\\": {
\\"type\\": \\"object\\",
\\"properties\\": {
\\"id\\": {
\\"type\\": \\"string\\"
},
\\"name\\": {
\\"type\\": \\"string\\"
},
\\"element\\": {
\\"type\\": \\"object\\",
\\"properties\\": {
\\"price\\": {
\\"type\\": \\"number\\",
\\"format\\": \\"float\\",
\\"example\\": 12,
\\"maximum\\": 99.95,
\\"multipleOf\\": 4,
\\"description\\": \\"property-schemaprop description for float inner object\\"
}
},
\\"required\\": [
\\"price\\"
],
\\"minProperties\\": 1,
\\"maxProperties\\": 100,
\\"description\\": \\"property-schemaprop description for object\\"
},
\\"currencies\\": {
\\"type\\": \\"array\\",
\\"items\\": {
\\"type\\": \\"string\\"
},
\\"minItems\\": 1,
\\"maxItems\\": 5,
\\"uniqueItems\\": true,
\\"description\\": \\"property-schemaprop description for array\\"
},
\\"code\\": {
\\"type\\": \\"string\\",
\\"enum\\": [
\\"VALID\\",
\\"NOT_VALID\\",
\\"WAITING\\",
\\"APPROVED\\"
],
\\"title\\": \\"process-code\\",
\\"description\\": \\"property-schemaprop description for union\\"
},
\\"inheritance\\": {
\\"allOf\\": [
{
\\"type\\": \\"object\\",
\\"properties\\": {
\\"inheritId\\": {
\\"type\\": \\"number\\",
\\"format\\": \\"double\\",
\\"example\\": 12,
\\"maximum\\": 99.95,
\\"multipleOf\\": 4,
\\"description\\": \\"property-schemaprop description for double inner intersection\\"
}
},
\\"required\\": [
\\"inheritId\\"
]
},
{
\\"type\\": \\"object\\",
\\"properties\\": {
\\"inheritName\\": {
\\"type\\": \\"integer\\",
\\"format\\": \\"int64\\",
\\"minimum\\": 1,
\\"default\\": 42,
\\"description\\": \\"property-schemaprop description for long inner intersection\\"
}
},
\\"required\\": [
\\"inheritName\\"
]
}
],
\\"title\\": \\"process-code\\",
\\"description\\": \\"property-schemaprop description for intersection\\"
}
},
\\"required\\": [
\\"id\\",
\\"name\\",
\\"element\\"
]
}
}
}
}
}
}
}
}"
`;

exports[`OpenAPI 2 generator security contract with security header 1`] = `
"{
\\"swagger\\": \\"2.0\\",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import {
api,
body,
endpoint,
headers,
request,
response,
String,
Integer,
Float,
Int64,
Double
} from "@airtasker/spot";

@api({ name: "contract" })
class Contract {}

@endpoint({
method: "GET",
path: "/users"
})
class EndpointWithSchemaPropsOnHeaders {
@request
request(
@headers
headers: {
/** property-schemaprop description for string
* @oaSchemaProp minLength
* 12
* @oaSchemaProp maxLength
* 20
* @oaSchemaProp pattern
* "^[0-9a-z_]+$"
* */
status: String;
/** property-schemaprop description for integer
* @oaSchemaProp minimum
* 1
* @default 42
* */
size: Integer;
}
) {}

@response({ status: 200 })
successResponse(
@body
body: {
id: String;
name: String;
/** property-schemaprop description for object
* @oaSchemaProp minProperties
* 1
* @oaSchemaProp maxProperties
* 100
* */
element: {
/** property-schemaprop description for float inner object
* @oaSchemaProp example
* 12.0
* @oaSchemaProp maximum
* 99.95
* @oaSchemaProp multipleOf
* 4
* */
price: Float;
};
/** property-schemaprop description for array
* @oaSchemaProp minItems
* 1
* @oaSchemaProp maxItems
* 5
* @oaSchemaProp uniqueItems
* true
* */
currencies?: String[];
/** property-schemaprop description for union
* @oaSchemaProp title
* "process-code"
* */
code?: "VALID" | "NOT_VALID" | "WAITING" | "APPROVED";
/** property-schemaprop description for intersection
* @oaSchemaProp title
* "process-code"
* */
inheritance?: {
/** property-schemaprop description for double inner intersection
* @oaSchemaProp example
* 12.0
* @oaSchemaProp maximum
* 99.95
* @oaSchemaProp multipleOf
* 4
* */
inheritId: Double;
} & {
/** property-schemaprop description for long inner intersection
* @oaSchemaProp minimum
* 1
* @default 42
* */
inheritName: Int64;
};
}[]
) {}
}
Loading