Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,12 @@ public void preprocessSwagger(Swagger swagger) {
if (info.getTitle() != null) {
// when info.title is defined, use it for projectName
// used in package.json
projectName = dashize(info.getTitle());
projectName = info.getTitle()
.replaceAll("[^a-zA-Z0-9]", "-")
.replaceAll("^[-]*", "")
.replaceAll("[-]*$", "")
.replaceAll("[-]{2,}", "-")
.toLowerCase();
this.additionalProperties.put("projectName", projectName);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

import mockit.Expectations;
import mockit.Tested;
import org.testng.annotations.Test;

import static org.testng.Assert.assertEquals;

public class NodeJSServerOptionsTest extends AbstractOptionsTest {

Expand All @@ -32,4 +35,27 @@ protected void setExpectations() {
times = 1;
}};
}


@Test
public void testCleanTitle() {
String dirtyTitle = "safe-title";
String clean = dirtyTitle.replaceAll("[^a-zA-Z0-9]", "-")
.replaceAll("^[-]*", "")
.replaceAll("[-]*$", "")
.replaceAll("[-]{2,}", "-");

assertEquals(clean, "safe-title");
}

@Test
public void testDirtyTitleCleansing() {
String dirtyTitle = "_it's-$ooo//////////---_//dirty!!!!";
String clean = dirtyTitle.replaceAll("[^a-zA-Z0-9]", "-")
.replaceAll("^[-]*", "")
.replaceAll("[-]*$", "")
.replaceAll("[-]{2,}", "-");

assertEquals(clean, "it-s-ooo-dirty");
}
}
5 changes: 2 additions & 3 deletions samples/server/petstore/nodejs/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ paths:
description: "ID of pet that needs to be fetched"
required: true
type: "integer"
maximum: 5
minimum: 1
maximum: 5.0
minimum: 1.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fehguy The output is now a decimal instead of integer: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml#L343-L344

I don't think it's related to the change in this PR, probably due to changes in the Swagger Parser.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #4649 for tracking.

format: "int64"
responses:
200:
Expand Down Expand Up @@ -385,7 +385,6 @@ paths:
description: "ID of the order that needs to be deleted"
required: true
type: "string"
minimum: 1
responses:
400:
description: "Invalid ID supplied"
Expand Down