Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Philzen committed Jun 3, 2024
1 parent 997cfa8 commit 47801e3
Show file tree
Hide file tree
Showing 4 changed files with 466 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,43 @@ public void testInputSpecRootDirectoryDoesNotRequireInputSpec() throws Exception
assertTrue(hashFolder.resolve("_merged_spec.yaml-executionId.sha256").toFile().exists());
}

/**
* Regression test for <a href="https://github.com/OpenAPITools/openapi-generator/issues/4512">#4512</a>
*/
public void test_skipIfSpecIsUnchanged_WillNotGenerateTwice_forMultipleExecutions_withIdenticalFilenames() throws Exception {

//GIVEN
/* Setup the mojo */
final Path tempDir = newTempFolder();
final CodeGenMojo mojo = loadMojo(tempDir, "src/test/resources/issue-4512", null, "execution_petstore1");
mojo.inputSpecRootDirectory = tempDir.toString();


/* Perform an initial generation */
mojo.execute();

/* Check the hash file was created */
final Path hashFolder = tempDir.resolve("target/generated-sources/issue-4512/.openapi-generator");
assertTrue(hashFolder.resolve("petstore.yaml-execution_petstore1.sha256").toFile().exists());
assertTrue(hashFolder.resolve("petstore.yaml-execution_petstore2.sha256").toFile().exists());

/* Remove the generated source */
FileUtils.deleteDirectory(tempDir.resolve("target/generated-sources/issue-4512/src").toFile());


// WHEN
/* Execute the mojo again */
mojo.execute();

// THEN
/* Verify that the source directory has not been repopulated. If it has then we generated code again */
assertFalse(
"src directory should not have been regenerated",
tempDir.resolve("target/generated-sources/issue-4512/src").toFile().exists()
);

}

protected CodeGenMojo loadMojo(Path temporaryFolder, String projectRoot, String profile) throws Exception {
return loadMojo(temporaryFolder, projectRoot, profile, "default");
}
Expand All @@ -236,6 +273,8 @@ protected CodeGenMojo loadMojo(Path temporaryFolder, String projectRoot, String
MojoExecution execution = newMojoExecution("generate");
MojoExecution executionWithId = copyWithExecutionId(executionId, execution);
return (CodeGenMojo) lookupConfiguredMojo(session, executionWithId);
// codegenMojo.inputSpecRootDirectory = temporaryFolder.toString();
// return codegenMojo;
}

private MojoExecution copyWithExecutionId(String executionId, MojoExecution execution) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
openapi: 3.0.0
servers:
- url: 'http://petstore.swagger.io/v2'
info:
description: This is a sample Petstore **ONE** server.
version: 1.0.0
title: OpenAPI Petstore
paths:
/pet:
post:
tags:
- pet
summary: Add a new pet to the store
description: ''
operationId: addPet
responses:
'200':
description: successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'405':
description: Invalid input
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
$ref: '#/components/requestBodies/Pet'
'/pet/{petId}':
get:
tags:
- pet
summary: Find pet by ID
description: Returns a single pet
operationId: getPetById
parameters:
- name: petId
in: path
description: ID of pet to return
required: true
schema:
type: integer
format: int64
responses:
'200':
description: successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'400':
description: Invalid ID supplied
'404':
description: Pet not found
security:
- api_key: []
post:
tags:
- pet
summary: Updates a pet in the store with form data
description: ''
operationId: updatePetWithForm
parameters:
- name: petId
in: path
description: ID of pet that needs to be updated
required: true
schema:
type: integer
format: int64
responses:
'405':
description: Invalid input
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
name:
description: Updated name of the pet
type: string
status:
description: Updated status of the pet
type: string
delete:
tags:
- pet
summary: Deletes a pet
description: ''
operationId: deletePet
parameters:
- name: api_key
in: header
required: false
schema:
type: string
- name: petId
in: path
description: Pet id to delete
required: true
schema:
type: integer
format: int64
responses:
'400':
description: Invalid pet value
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
components:
requestBodies:
Pet:
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
description: Pet object that needs to be added to the store
required: true
securitySchemes:
petstore_auth:
type: oauth2
flows:
implicit:
authorizationUrl: 'http://petstore.swagger.io/api/oauth/dialog'
scopes:
'write:pets': modify pets in your account
'read:pets': read your pets
api_key:
type: apiKey
name: api_key
in: header
schemas:
Pet:
title: a Pet
description: A pet for sale in the pet store
type: object
required:
- name
- photoUrls
properties:
id:
type: integer
format: int64
name:
type: string
example: doggie
photoUrls:
type: array
xml:
name: photoUrl
wrapped: true
items:
type: string
status:
type: string
description: pet status in the store
enum:
- available
- pending
- sold
xml:
name: Pet
Loading

0 comments on commit 47801e3

Please sign in to comment.