-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: API-28061 - update example request body generation (#150)
* feat(positive suite): aPI-28061 - Update request body generation Create example request body from MediaTypeObject.example if present. Create a request body using only required fields as well as the entire example. * refactor: aPI-28061 - refactor request body building * test: aPI-28061 - update tests and add new tests * refactor: aPI-28061 - rename required fields request body constant * refactor: aPI-28061 - refactor OperationExampleFactory and tests * refactor(operationexamplefactory): aPI-28061 - update operation-example.factory.ts logic * docs: aPI-28061 - add comments to RequestBodyFactory and OperationExampleFactory * ci(jenkinsfile): aPI-28061 - test using ghcr DockerImage for building LOAST * docs(readme): aPI-28016 - update README Example Request Body section * revert(jenkinsfile): aPI-28061 - undo Jenkinsfile changes
- Loading branch information
1 parent
78673c1
commit 9b0313b
Showing
21 changed files
with
749 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
41 changes: 28 additions & 13 deletions
41
src/oas-parsing/operation-example/operation-example.factory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,39 @@ | ||
/** | ||
* The OperationExampleFactory class is responsible for building OperationExamples for all Operations that are part of the OAS under test. | ||
* An Operation could potentially have both multiple ExampleGroups (query, path, or header parameters) | ||
* and multiple ExampleRequestBodies (a request body with only required fields and a request body with required and optional fields). | ||
* OperationExamples will be created for each permutation of ExampleGroups and ExampleRequestBodies | ||
* (if an Operation has 2 ExampleGroups and 2 ExampleRequestBodies, then 4 OperationExamples will be created for that Operation). | ||
*/ | ||
|
||
import ExampleGroup from '../example-group/example-group'; | ||
import OASOperation from '../operation/oas-operation'; | ||
import OperationExample from './operation-example'; | ||
|
||
export default class OperationExampleFactory { | ||
public static buildFromOperations( | ||
operations: OASOperation[], | ||
): OperationExample[] { | ||
const operationExamples: OperationExample[] = []; | ||
|
||
for (const operation of operations) { | ||
const exampleGroups = operation.exampleGroups; | ||
return operations.flatMap((operation) => | ||
this.buildFromOperation(operation), | ||
); | ||
} | ||
|
||
for (const exampleGroup of exampleGroups) { | ||
operationExamples.push({ | ||
operation, | ||
exampleGroup, | ||
requestBody: operation.exampleRequestBody, | ||
}); | ||
} | ||
} | ||
private static buildFromOperation( | ||
operation: OASOperation, | ||
): OperationExample[] { | ||
return operation.exampleGroups.flatMap((exampleGroup) => | ||
this.buildFromOperationAndExampleGroup(operation, exampleGroup), | ||
); | ||
} | ||
|
||
return operationExamples; | ||
private static buildFromOperationAndExampleGroup( | ||
operation: OASOperation, | ||
exampleGroup: ExampleGroup, | ||
): OperationExample[] { | ||
return operation.exampleRequestBodies.map( | ||
(exampleRequestBody) => | ||
new OperationExample(operation, exampleGroup, exampleRequestBody), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,29 @@ | ||
import { RequestBody } from 'swagger-client'; | ||
import { NO_REQUEST_BODY } from '../../utilities/constants'; | ||
import ExampleGroup from '../example-group/example-group'; | ||
import OASOperation from '../operation/oas-operation'; | ||
import ExampleRequestBody from '../request-body/example-request-body'; | ||
|
||
export default class OperationExample { | ||
readonly operation: OASOperation; | ||
|
||
readonly exampleGroup: ExampleGroup; | ||
|
||
readonly requestBody: RequestBody; | ||
readonly exampleRequestBody: ExampleRequestBody; | ||
|
||
readonly name: string; | ||
|
||
constructor( | ||
operation: OASOperation, | ||
exampleGroup: ExampleGroup, | ||
requestBody: RequestBody, | ||
exampleRequestBody: ExampleRequestBody, | ||
) { | ||
this.operation = operation; | ||
this.exampleGroup = exampleGroup; | ||
this.requestBody = requestBody; | ||
this.exampleRequestBody = exampleRequestBody; | ||
|
||
this.name = | ||
exampleRequestBody.name === NO_REQUEST_BODY | ||
? exampleGroup.name | ||
: `${exampleGroup.name} - ${exampleRequestBody.name}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { RequestBody } from 'swagger-client'; | ||
|
||
class ExampleRequestBody { | ||
readonly name: string; | ||
readonly requestBody: RequestBody; | ||
|
||
constructor(name: string, requestBody: RequestBody) { | ||
this.name = name; | ||
this.requestBody = requestBody; | ||
} | ||
} | ||
|
||
export default ExampleRequestBody; |
Oops, something went wrong.