-
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.
- Loading branch information
Showing
18 changed files
with
472 additions
and
84 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
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,30 @@ | ||
package names | ||
|
||
import "strings" | ||
|
||
func Deduplicate(names []string) []string { | ||
dups := make(map[int]bool, len(names)-1) | ||
for i := range names { | ||
for j := range names { | ||
if i == j { | ||
continue | ||
} | ||
ni := strings.ToLower(names[i]) | ||
nj := strings.ToLower(names[j]) | ||
if strings.Contains(ni, nj) { | ||
dups[j] = true | ||
} else if strings.Contains(nj, ni) { | ||
dups[i] = true | ||
} | ||
} | ||
} | ||
|
||
result := make([]string, 0, len(names)-len(dups)) | ||
for idx, name := range names { | ||
if !dups[idx] { | ||
result = append(result, name) | ||
} | ||
} | ||
|
||
return result | ||
} |
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,27 @@ | ||
package names_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/jxsl13/openapi-typegen/names" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDeduplicate(t *testing.T) { | ||
in := []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"} | ||
expected := []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"} | ||
out := names.Deduplicate(in) | ||
|
||
assert.Equal(t, expected, out) | ||
|
||
in = []string{"a", "b", "c", "d", "ef", "f", "g", "h", "i", "j"} | ||
expected = []string{"a", "b", "c", "d", "ef", "g", "h", "i", "j"} | ||
out = names.Deduplicate(in) | ||
assert.Equal(t, expected, out) | ||
|
||
in = []string{"a", "bd", "c", "d", "ef", "f", "g", "gh", "i", "j"} | ||
expected = []string{"a", "bd", "c", "ef", "gh", "i", "j"} | ||
out = names.Deduplicate(in) | ||
assert.Equal(t, expected, out) | ||
|
||
} |
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,164 @@ | ||
openapi: 3.0.1 | ||
|
||
info: | ||
title: OpenAPI-CodeGen Test | ||
description: 'This is a test OpenAPI Spec' | ||
version: 1.0.0 | ||
|
||
servers: | ||
- url: https://test.oapi-codegen.com/v2 | ||
- url: http://test.oapi-codegen.com/v2 | ||
|
||
paths: | ||
/test: | ||
get: | ||
operationId: doesNothing | ||
summary: does nothing | ||
tags: [nothing] | ||
responses: | ||
default: | ||
description: returns nothing | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
components: | ||
schemas: | ||
Object1: | ||
type: object | ||
properties: | ||
object: | ||
$ref: "#/components/schemas/Object2" | ||
Object2: | ||
type: object | ||
properties: | ||
object: | ||
$ref: "#/components/schemas/Object3" | ||
Object3: | ||
type: object | ||
properties: | ||
object: | ||
$ref: "#/components/schemas/Object4" | ||
Object4: | ||
type: object | ||
properties: | ||
object: | ||
$ref: "#/components/schemas/Object5" | ||
Object5: | ||
type: object | ||
properties: | ||
object: | ||
$ref: "#/components/schemas/Object6" | ||
Object6: | ||
type: object | ||
Pet: | ||
type: object | ||
required: | ||
- id | ||
- name | ||
properties: | ||
id: | ||
type: integer | ||
format: int64 | ||
name: | ||
type: string | ||
tag: | ||
type: string | ||
Error: | ||
required: | ||
- code | ||
- message | ||
properties: | ||
code: | ||
type: integer | ||
format: int32 | ||
description: Error code | ||
message: | ||
type: string | ||
description: Error message | ||
parameters: | ||
offsetParam: | ||
name: offset | ||
in: query | ||
description: Number of items to skip before returning the results. | ||
required: false | ||
schema: | ||
type: integer | ||
format: int32 | ||
minimum: 0 | ||
default: 0 | ||
securitySchemes: | ||
BasicAuth: | ||
type: http | ||
scheme: basic | ||
BearerAuth: | ||
type: http | ||
scheme: bearer | ||
requestBodies: | ||
PetBody: | ||
description: A JSON object containing pet information | ||
required: true | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/Pet' | ||
responses: | ||
NotFound: | ||
description: The specified resource was not found | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/Error' | ||
Unauthorized: | ||
description: Unauthorized | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/Error' | ||
headers: | ||
X-RateLimit-Limit: | ||
schema: | ||
type: integer | ||
description: Request limit per hour. | ||
X-RateLimit-Remaining: | ||
schema: | ||
type: integer | ||
description: The number of requests left for the time window. | ||
X-RateLimit-Reset: | ||
schema: | ||
type: string | ||
format: date-time | ||
description: The UTC date/time at which the current rate limit window resets | ||
examples: | ||
objectExample: | ||
value: | ||
id: 1 | ||
name: new object | ||
summary: A sample object | ||
links: | ||
GetUserByUserId: | ||
description: > | ||
The id value returned in the response can be used as | ||
the userId parameter in GET /users/{userId}. | ||
operationId: getUser | ||
parameters: | ||
userId: '$response.body#/id' | ||
callbacks: | ||
MyCallback: | ||
'{$request.body#/callbackUrl}': | ||
post: | ||
requestBody: | ||
required: true | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
properties: | ||
message: | ||
type: string | ||
example: Some event happened | ||
required: | ||
- message | ||
responses: | ||
'200': | ||
description: Your server returns this code if it accepts the callback |
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
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
Oops, something went wrong.