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

Generate User Types API with swagger-codegen #305

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ab8b853
add swagger-codegen templates (typescript-axios)
oleksandrpravosudko-okta Feb 21, 2022
8220645
first pass on generating User Type API client
oleksandrpravosudko-okta Feb 22, 2022
8853574
fix v3 client return type
oleksandrpravosudko-okta Feb 23, 2022
ef102df
include v3 models into index
oleksandrpravosudko-okta Feb 23, 2022
27790a2
add integration test for User Type API
oleksandrpravosudko-okta Feb 23, 2022
525c7c8
rename apiKey -> apiToken
oleksandrpravosudko-okta Feb 23, 2022
ac9f03d
add placeholder imports for type modules
oleksandrpravosudko-okta Mar 7, 2022
52f86a9
add v3 typings
oleksandrpravosudko-okta Mar 7, 2022
eb24a96
replace TypeScript modules with JS + typings
oleksandrpravosudko-okta Mar 7, 2022
c1a43db
fix lint
oleksandrpravosudko-okta Mar 7, 2022
d3980ab
update template formatting
oleksandrpravosudko-okta Mar 8, 2022
fb404a1
add unused swagger-codegen output to gitignore
oleksandrpravosudko-okta Mar 8, 2022
a63ce8e
add v3 APIs index module
oleksandrpravosudko-okta Mar 8, 2022
948c776
add script for emitting V3 types
oleksandrpravosudko-okta Mar 8, 2022
547deac
fix lint errors
oleksandrpravosudko-okta Mar 8, 2022
16c6347
do not expose v3 models through package root
oleksandrpravosudko-okta Mar 8, 2022
e36d184
expose v2 models
oleksandrpravosudko-okta Mar 9, 2022
7e7341a
add instructions for generating SDK with swagger-codegen
oleksandrpravosudko-okta Mar 9, 2022
ee32e21
remove merge artifacts
oleksandrpravosudko-okta Mar 9, 2022
8fcc26c
fix eslint error
oleksandrpravosudko-okta Mar 9, 2022
7d7c239
correct import case
oleksandrpravosudko-okta Mar 9, 2022
ff70a8f
remove duplicate V2Configuration
oleksandrpravosudko-okta Mar 14, 2022
cfb016e
consistent indents in templates
oleksandrpravosudko-okta Mar 14, 2022
35e9f8d
expose v3 models through alias
oleksandrpravosudko-okta Mar 15, 2022
1f35685
wrap v3 exports into namespace
oleksandrpravosudko-okta Mar 15, 2022
3447e79
use classes for models for non-void JS output
oleksandrpravosudko-okta Mar 15, 2022
42fcfb8
fix lint
oleksandrpravosudko-okta Mar 15, 2022
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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@ test-reports/
.yalc
yalc.lock

src/v3/.swagger-codegen/
src/v3/.gitignore
src/v3/.npmignore
src/v3/.swagger-codegen-ignore
src/v3/git_push.sh
src/v3/README.md
src/v3/tsconfig.json
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,14 @@ This version 4.0 release also updated APIs latest `@okta/openapi` (v2.0.0) that

Run `yarn build` from repository root.

### Building with swagger-codegen
- Obtain OASv3 combined spec
- Install [swagger-codegen](https://github.com/swagger-api/swagger-codegen/tree/3.0.0#homebrew)
- run `swagger-codegen generate -i ./path/to/specfile.yaml|json -o ./src/v3 -l typescript-axios -t ./templates/swagger-codegen`
- remove APIs and models which are not intended to be pushed to upstream from `src/v3`
- run `./scripts/emitV3Types.sh` to replace TypeScript modules with typings + javascript modules
- commit changes

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md) if you would like to propose changes to this library.
Expand Down
3 changes: 3 additions & 0 deletions scripts/emitV3Types.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tsc src/v3/**/*.ts --declaration
rsync -r src/v3/**/*.d.ts src/types/v3
find src/v3/ -type f ! -name "*.js" -delete
2 changes: 2 additions & 0 deletions src/configuration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// no js code for V2Configuration, it is only used as a type in TypeScript modules
module.exports = {};
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ module.exports = Object.assign(
DefaultRequestExecutor: require('./default-request-executor'),
Collection: require('./collection'),
},
require('./models')
require('./models'),
require('./v3')
);
18 changes: 2 additions & 16 deletions src/types/client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,10 @@ import { ParameterizedOperationsClient } from './parameterized-operations-client
import { OAuth } from './oauth';
import { Http } from './http';
import { RequestExecutor } from './request-executor';
import { defaultCacheMiddleware } from './default-cache-middleware';
import { CacheStorage } from './memory-store';

import { V2Configuration } from './configuration';

export declare class Client extends ParameterizedOperationsClient {
constructor(config?: {
orgUrl?: string,
token?: string,
clientId?: string,
scopes?: string[],
requestExecutor?: RequestExecutor,
authorizationMode?: string,
privateKey?: string | Record<string, unknown>
cacheStore?: CacheStorage,
cacheMiddleware?: typeof defaultCacheMiddleware | unknown
defaultCacheMiddlewareResponseBufferSize?: number,
httpsProxy?: string | unknown, // https://github.com/TooTallNate/node-agent-base/issues/56
});
constructor(config?: V2Configuration);

requestExecutor: RequestExecutor;
authorizationMode: string;
Expand Down
3 changes: 2 additions & 1 deletion src/types/config-loader.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export declare class ConfigLoader {
token: string;
clientId: string;
scopes: string;
privateKey: string;
privateKey?: string;
userAgent?: string;
};
};
applyDefaults(): void;
Expand Down
15 changes: 15 additions & 0 deletions src/types/configuration.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { defaultCacheMiddleware } from './default-cache-middleware';
import { RequestExecutor } from './request-executor';

export declare interface V2Configuration {
orgUrl?: string,
token?: string,
clientId?: string,
scopes?: string[],
requestExecutor?: RequestExecutor,
authorizationMode?: string,
privateKey?: string | Record<string, unknown>
cacheStore?: CacheStorage,
cacheMiddleware?: typeof defaultCacheMiddleware | unknown
defaultCacheMiddlewareResponseBufferSize?: number,
}
3 changes: 2 additions & 1 deletion src/types/http.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export declare class Http {
oauth: OAuth,
cacheStore?: CacheStorage,
cacheMiddleware?: typeof defaultCacheMiddleware | unknown,
httpsProxy?: string | unknown, // https://github.com/TooTallNate/node-agent-base/issues/56
httpsProxy?: string | unknown, // https://github.com/TooTallNate/node-agent-base/issues/56,
defaultCacheMiddlewareResponseBufferSize?: number,
});
defaultHeaders: Record<string, unknown>;
requestExecutor: RequestExecutor;
Expand Down
1 change: 1 addition & 0 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export * from './request-options/SecurePasswordStoreApplicationOptions';
export * from './request-options/SwaApplicationOptions';
export * from './request-options/SwaThreeFieldApplicationOptions';
export * from './request-options/WsFederationApplicationOptions';
export * from './v3';

export * from './models/AccessPolicy';
export * from './models/AccessPolicyConstraint';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@ declare interface SecurePasswordStoreApplicationOptions {
export {
SecurePasswordStoreApplicationOptions
};

12 changes: 12 additions & 0 deletions src/types/v3/api.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Okta API
* Allows customers to easily access the Okta API
*
* OpenAPI spec version: 2.10.0
* Contact: devex-public@okta.com
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
export * from './apis/user-type-api';
246 changes: 246 additions & 0 deletions src/types/v3/apis/user-type-api.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
/**
* Okta API
* Allows customers to easily access the Okta API
*
* OpenAPI spec version: 2.10.0
* Contact: devex-public@okta.com
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
import { RequestArgs, BaseAPI } from '../base';
import { UserType } from '../models';
import { Response } from 'node-fetch';
import Http = require('../../http');
import { V2Configuration } from '../../configuration';
import { Configuration } from '../configuration';
/**
* UserTypeApi - request parameter creator
* @export
*/
export declare const UserTypeApiRequestParamCreator: (configuration?: Configuration & V2Configuration) => {
httpClient: any;
/**
* Creates a new User Type. A default User Type is automatically created along with your org, and you may add another 9 User Types for a maximum of 10.
* @summary Create User Type
* @param {UserType} body
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
createUserType: (body: UserType, options?: any) => Promise<RequestArgs>;
/**
* Deletes a User Type permanently. This operation is not permitted for the default type, nor for any User Type that has existing users
* @summary Delete User Type
* @param {string} typeId
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
deleteUserType: (typeId: string, options?: any) => Promise<RequestArgs>;
/**
* Fetches a User Type by ID. The special identifier `default` may be used to fetch the default User Type.
* @summary Get User Type
* @param {string} typeId
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getUserType: (typeId: string, options?: any) => Promise<RequestArgs>;
/**
* Fetches all User Types in your org
* @summary List User Types
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
listUserTypes: (options?: any) => Promise<RequestArgs>;
/**
* Replace an existing User Type
* @summary Replace User Type
* @param {UserType} body
* @param {string} typeId
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
replaceUserType: (body: UserType, typeId: string, options?: any) => Promise<RequestArgs>;
/**
* Updates an existing User Type
* @summary Update User Type
* @param {UserType} body
* @param {string} typeId
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
updateUserType: (body: UserType, typeId: string, options?: any) => Promise<RequestArgs>;
};
/**
* UserTypeApi - functional programming interface
* @export
*/
export declare const UserTypeApiFp: (configuration?: Configuration & V2Configuration) => {
/**
* Creates a new User Type. A default User Type is automatically created along with your org, and you may add another 9 User Types for a maximum of 10.
* @summary Create User Type
* @param {UserType} body
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
createUserType(body: UserType, options?: any): Promise<(httpClient?: any, basePath?: string) => Promise<UserType>>;
/**
* Deletes a User Type permanently. This operation is not permitted for the default type, nor for any User Type that has existing users
* @summary Delete User Type
* @param {string} typeId
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
deleteUserType(typeId: string, options?: any): Promise<(httpClient?: any, basePath?: string) => Promise<Response>>;
/**
* Fetches a User Type by ID. The special identifier `default` may be used to fetch the default User Type.
* @summary Get User Type
* @param {string} typeId
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getUserType(typeId: string, options?: any): Promise<(httpClient?: any, basePath?: string) => Promise<UserType>>;
/**
* Fetches all User Types in your org
* @summary List User Types
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
listUserTypes(options?: any): Promise<(httpClient?: any, basePath?: string) => Promise<Array<UserType>>>;
/**
* Replace an existing User Type
* @summary Replace User Type
* @param {UserType} body
* @param {string} typeId
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
replaceUserType(body: UserType, typeId: string, options?: any): Promise<(httpClient?: any, basePath?: string) => Promise<UserType>>;
/**
* Updates an existing User Type
* @summary Update User Type
* @param {UserType} body
* @param {string} typeId
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
updateUserType(body: UserType, typeId: string, options?: any): Promise<(httpClient?: any, basePath?: string) => Promise<UserType>>;
};
/**
* UserTypeApi - factory interface
* @export
*/
export declare const UserTypeApiFactory: (configuration?: Configuration, basePath?: string, httpClient?: any) => {
/**
* Creates a new User Type. A default User Type is automatically created along with your org, and you may add another 9 User Types for a maximum of 10.
* @summary Create User Type
* @param {UserType} body
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
createUserType(body: UserType, options?: any): Promise<UserType>;
/**
* Deletes a User Type permanently. This operation is not permitted for the default type, nor for any User Type that has existing users
* @summary Delete User Type
* @param {string} typeId
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
deleteUserType(typeId: string, options?: any): Promise<Response>;
/**
* Fetches a User Type by ID. The special identifier `default` may be used to fetch the default User Type.
* @summary Get User Type
* @param {string} typeId
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getUserType(typeId: string, options?: any): Promise<UserType>;
/**
* Fetches all User Types in your org
* @summary List User Types
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
listUserTypes(options?: any): Promise<Array<UserType>>;
/**
* Replace an existing User Type
* @summary Replace User Type
* @param {UserType} body
* @param {string} typeId
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
replaceUserType(body: UserType, typeId: string, options?: any): Promise<UserType>;
/**
* Updates an existing User Type
* @summary Update User Type
* @param {UserType} body
* @param {string} typeId
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
updateUserType(body: UserType, typeId: string, options?: any): Promise<UserType>;
};
/**
* UserTypeApi - object-oriented interface
* @export
* @class UserTypeApi
* @extends {BaseAPI}
*/
export declare class UserTypeApi extends BaseAPI {
/**
* Creates a new User Type. A default User Type is automatically created along with your org, and you may add another 9 User Types for a maximum of 10.
* @summary Create User Type
* @param {UserType} body
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof UserTypeApi
*/
createUserType(body: UserType, options?: any): Promise<UserType>;
/**
* Deletes a User Type permanently. This operation is not permitted for the default type, nor for any User Type that has existing users
* @summary Delete User Type
* @param {string} typeId
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof UserTypeApi
*/
deleteUserType(typeId: string, options?: any): Promise<Response>;
/**
* Fetches a User Type by ID. The special identifier `default` may be used to fetch the default User Type.
* @summary Get User Type
* @param {string} typeId
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof UserTypeApi
*/
getUserType(typeId: string, options?: any): Promise<UserType>;
/**
* Fetches all User Types in your org
* @summary List User Types
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof UserTypeApi
*/
listUserTypes(options?: any): Promise<UserType[]>;
/**
* Replace an existing User Type
* @summary Replace User Type
* @param {UserType} body
* @param {string} typeId
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof UserTypeApi
*/
replaceUserType(body: UserType, typeId: string, options?: any): Promise<UserType>;
/**
* Updates an existing User Type
* @summary Update User Type
* @param {UserType} body
* @param {string} typeId
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof UserTypeApi
*/
updateUserType(body: UserType, typeId: string, options?: any): Promise<UserType>;
}
Loading