-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixups.js
168 lines (160 loc) · 6.25 KB
/
fixups.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/**
* @copyright Copyright 2021 Kevin Locke <kevin@kevinlocke.name>
* @license MIT
* @module "procore-docs-to-openapi/fixups.js"
*/
import BoolEnumToBoolTransformer
from '@kevinoid/openapi-transformers/bool-enum-to-bool.js';
import NullableToTypeNullTransformer
from '@kevinoid/openapi-transformers/nullable-to-type-null.js';
import RemoveQueryFromPathsTransformer
from '@kevinoid/openapi-transformers/remove-query-from-paths.js';
import OpenApiTransformerBase from 'openapi-transformer-base';
import DateEnumTransformer from './lib/date-enum-transformer.js';
import DeprecatedTransformer from './lib/deprecated-transformer.js';
import DocBugsTransformer from './lib/doc-bugs-transformer.js';
import ErrorResponseTransformer from './lib/error-response-transformer.js';
import FormatFromContextTransformer
from './lib/format-from-context-transformer.js';
import MultipartTransformer from './lib/multipart-transformer.js';
import TimeMinMaxTransformer from './lib/time-min-max-transformer.js';
/** OpenAPI Transformer to apply various fix-ups to the OpenAPI document
* generated directly from the Procore API documentation JSON.
*/
export default class ProcoreFixupsTransformer extends OpenApiTransformerBase {
constructor() {
super();
this.transformers = [
new DocBugsTransformer(),
new RemoveQueryFromPathsTransformer(),
new BoolEnumToBoolTransformer(),
new NullableToTypeNullTransformer(),
new DateEnumTransformer(),
new TimeMinMaxTransformer(),
new FormatFromContextTransformer(),
new DeprecatedTransformer(),
new MultipartTransformer(),
new ErrorResponseTransformer(),
];
}
transformOpenApi(openApi) {
if (typeof openApi !== 'object'
|| openApi === null
|| Array.isArray(openApi)) {
this.warn('Ignoring non-object OpenAPI', openApi);
return openApi;
}
for (const transformer of this.transformers) {
openApi = transformer.transformOpenApi(openApi);
}
const securityScheme = {
type: 'oauth2',
/* eslint-disable max-len */
description: `OAuth 2.0 Authentication.
See: https://developers.procore.com/documentation/oauth-introduction
Documentation for Flows (i.e. Grant Types):\\
Authorization Code: https://developers.procore.com/documentation/oauth-auth-grant-flow\\
Client Credentials: https://developers.procore.com/documentation/oauth-client-credentials\\
Implicit: https://developers.procore.com/documentation/oauth-implicit-flow`,
/* eslint-enable max-len */
flows: {
authorizationCode: {
authorizationUrl:
'https://login.procore.com/oauth/authorize?response_type=code',
tokenUrl:
'https://api.procore.com/oauth/authorize?response_type=code',
refreshUrl: 'https://api.procore.com/oauth/token',
scopes: {},
},
clientCredentials: {
tokenUrl: 'https://login.procore.com/oauth/token',
refreshUrl: 'https://api.procore.com/oauth/token',
scopes: {},
},
implicit: {
authorizationUrl:
'https://api.procore.com/oauth/authorize?response_type=token',
refreshUrl: 'https://api.procore.com/oauth/token',
scopes: {},
},
},
};
const securitySchemeJson = JSON.stringify(securityScheme);
return {
info: {
title: 'Procore REST API',
version: '1.0.0',
description:
// From https://developers.procore.com/documentation/introduction
'Procore\'s open Application Programming Interface (API) provides the underlying framework for developing applications and custom integrations between Procore and other software tools and technologies.',
contact: {
name: 'Procore Developer Support',
email: 'apisupport@procore.com',
url: 'https://developers.procore.com/developer_support',
},
termsOfService: 'https://developers.procore.com/terms_and_conditions',
license: {
name: 'Procore API License and Application Developer Agreement',
url: 'https://developers.procore.com/terms_and_conditions',
},
'x-apiClientRegistration': 'https://developers.procore.com/signup',
'x-apisguru-categories': [
'project_management',
],
'x-description-language': 'en',
'x-logo': {
backgroundColor: '#FFFFFF',
// From https://www.procore.design/logos/
// Full Logo:
url: 'https://www.procore.design/images/procore_logo_fc_k.png',
// "C" Icon Only:
// 'https://www.procore.design/images/procore_graphicmark_fc_k.png',
},
'x-unofficialSpec': true,
},
externalDocs: {
description: 'Procore Developer Documentation',
url: 'https://developers.procore.com/documentation',
},
servers: [
{
url: 'https://api.procore.com',
description: 'Production',
},
// https://developers.procore.com/documentation/development-environments
{
url: 'https://api-monthly.procore.com',
description:
'**Monthly Sandbox** - refreshed with current production data on a regularly scheduled basis once each month.',
},
{
url: 'https://sandbox.procore.com',
description:
'**Development Sandbox** - automatically generated for third-party developers in their Developer Portal account and includes seed project data that can be used for testing purposes.',
},
],
// FIXME: Want to require security scheme corresponding to server
// https://github.com/OAI/OpenAPI-Specification/issues/2628
security: [
{ apiSecurity: [] },
{ monthlySecurity: [] },
{ sandboxSecurity: [] },
],
...openApi,
components: {
...openApi.components,
securitySchemes: {
apiSecurity: securityScheme,
monthlySecurity: JSON.parse(securitySchemeJson.replaceAll(
'https://login.procore.com',
'https://login-sandbox-monthly.procore.com',
)),
sandboxSecurity: JSON.parse(securitySchemeJson.replaceAll(
'https://login.procore.com',
'https://login-sandbox.procore.com',
)),
},
},
};
}
}