Skip to content

Commit 1dd4d4c

Browse files
committed
feat: ServerObject and ServerVariableObject
1 parent 21fcf06 commit 1dd4d4c

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@omer-x/openapi-types",
3-
"version": "0.2.1",
3+
"version": "0.3.0",
44
"description": "TypeScript types for the OpenAPI Specification",
55
"keywords": [
66
"swagger",
@@ -72,6 +72,9 @@
7272
"./schema": {
7373
"types": "./dist/schema.d.ts"
7474
},
75+
"./server": {
76+
"types": "./dist/server.d.ts"
77+
},
7578
"./tag": {
7679
"types": "./dist/tag.d.ts"
7780
}

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { ComponentsObject } from "./components";
22
import type { InfoObject } from "./info";
33
import type { PathsObject } from "./paths";
4+
import { ServerObject } from "./server";
45
import type { TagObject } from "./tag";
56

67
type AtLeastOne<T, U = { [K in keyof T]: Pick<T, K> }> = Partial<T> & U[keyof U];
@@ -24,7 +25,7 @@ export type OpenApiDocument = {
2425
/**
2526
* An array of Server Objects, which provide connectivity information to a target server. If the servers property is not provided, or is an empty array, the default value would be a Server Object with a url value of /.
2627
*/
27-
servers?: unknown,
28+
servers?: ServerObject[],
2829
/**
2930
* The available paths and operations for the API.
3031
*/

src/server.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
export type ServerObject = {
2+
/**
3+
* A URL to the target host. This URL supports Server Variables and MAY be relative, to indicate that the host location is relative to the location where the OpenAPI document is being served. Variable substitutions will be made when a variable is named in {brackets}.
4+
*/
5+
url: string,
6+
/**
7+
* An optional string describing the host designated by the URL. CommonMark syntax MAY be used for rich text representation.
8+
*/
9+
description?: string,
10+
/**
11+
* A map between a variable name and its value. The value is used for substitution in the server's URL template.
12+
*/
13+
variables?: Record<string, ServerVariableObject>,
14+
}
15+
16+
export type ServerVariableObject = {
17+
/**
18+
* An enumeration of string values to be used if the substitution options are from a limited set. The array MUST NOT be empty.
19+
*/
20+
enum: string[],
21+
/**
22+
* The default value to use for substitution, which SHALL be sent if an alternate value is not supplied. Note this behavior is different than the Schema Object's treatment of default values, because in those cases parameter values are optional. If the enum is defined, the value MUST exist in the enum's values.
23+
*/
24+
default: string,
25+
/**
26+
* An optional description for the server variable. CommonMark syntax MAY be used for rich text representation.
27+
*/
28+
description: string,
29+
}

0 commit comments

Comments
 (0)