fix(#523): handle missing 200 and default response in swagger test generation#1469
Open
phos-web wants to merge 2 commits intocitrusframework:mainfrom
Open
fix(#523): handle missing 200 and default response in swagger test generation#1469phos-web wants to merge 2 commits intocitrusframework:mainfrom
phos-web wants to merge 2 commits intocitrusframework:mainfrom
Conversation
bbortt
requested changes
Feb 1, 2026
| } | ||
|
|
||
| if (response == null) { | ||
| Map.Entry<String, Response> firstEntry = operation.getValue().getResponses().entrySet().iterator().next(); |
Collaborator
There was a problem hiding this comment.
isn't firstEntry null if there are no responses at all? this will throw a NoSuchElementException in that case.
test:
@Test
public void shouldCreateClassFromSpecWithNoResponses() throws IOException {
SwaggerJavaTestGenerator generator = new SwaggerJavaTestGenerator();
generator.withAuthor("phos-web")
.withDescription("This is a sample test")
.usePackage("org.citrusframework")
.withFramework(UnitFramework.TESTNG);
generator.withMode(TestGenerator.GeneratorMode.SERVER);
generator.withSpec("org/citrusframework/swagger/api-with-no-responses.json");
generator.create();
verifyTest("PetApiClient_getPetById_IT");
verifyTestWithStatus("PetApiClient_updatePet_IT", "BAD_REQUEST");
}
Contributor
Author
There was a problem hiding this comment.
Changed it to
if (response == null && !operation.getValue().getResponses().isEmpty())
| try { | ||
| httpStatus = HttpStatus.valueOf(Integer.parseInt(firstEntry.getKey())); | ||
| } catch (NumberFormatException e) { | ||
| httpStatus = HttpStatus.OK; |
Collaborator
There was a problem hiding this comment.
Suggested change
| httpStatus = HttpStatus.OK; | |
| // Ignore, default value is already HttpStatus.OK; |
0502b8c to
f20c47c
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes the Swagger test generator crashing when an API operation defines no
200ordefaultresponse. The generator now falls back to the first available response in the spec and resolves its actual HTTP status code, instead of assuming a successful response always exists. If the status code cannot be resolved, the fallback remains200 OK.Related issue
Fixes #523