Skip to content

Commit

Permalink
airtasker#1367 Implementation for SchemaProps (airtasker#1376)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thodin3 committed May 4, 2021
1 parent 4bab59e commit 82bc169
Show file tree
Hide file tree
Showing 28 changed files with 1,784 additions and 166 deletions.
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 @@ -855,6 +855,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

0 comments on commit 82bc169

Please sign in to comment.