Skip to content
This repository was archived by the owner on Mar 16, 2025. It is now read-only.

Commit 9c7ca1b

Browse files
committed
primitive mapping test
1 parent 5fc5f17 commit 9c7ca1b

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

src/test/groovy/com/github/hauner/openapi/core/converter/DataTypeConverterPrimitiveTypeMappingSpec.groovy

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import io.openapiprocessor.core.converter.mapping.TypeMapping
2525
import io.openapiprocessor.core.framework.Framework
2626
import io.openapiprocessor.core.framework.FrameworkBase
2727
import io.openapiprocessor.core.model.Api
28+
import io.openapiprocessor.core.parser.ParserType
2829
import spock.lang.Specification
2930
import spock.lang.Unroll
3031

@@ -75,6 +76,54 @@ paths:
7576
parameter.dataType.name == 'ZonedDateTime'
7677
}
7778

79+
void "converts named primitive type to java type via global type mapping" () {
80+
def openApi = parse ("""\
81+
openapi: 3.0.2
82+
info:
83+
title: API
84+
version: 1.0.0
85+
86+
paths:
87+
/uuid:
88+
get:
89+
parameters:
90+
- in: query
91+
name: uuid
92+
schema:
93+
\$ref: '#/components/schemas/UUID'
94+
responses:
95+
'204':
96+
description: none
97+
98+
components:
99+
schemas:
100+
UUID:
101+
type: string
102+
""", parser)
103+
104+
when:
105+
def options = new ApiOptions(
106+
packageName: 'pkg',
107+
typeMappings: [
108+
new TypeMapping (
109+
'UUID',
110+
'java.util.UUID')
111+
])
112+
113+
Api api = new ApiConverter (options, new FrameworkBase ())
114+
.convert (openApi)
115+
116+
then:
117+
def itf = api.interfaces.first ()
118+
def ep = itf.endpoints.first ()
119+
def parameter = ep.parameters.first ()
120+
parameter.dataType.packageName == 'java.util'
121+
parameter.dataType.name == 'UUID'
122+
123+
where:
124+
parser << [ParserType.SWAGGER, ParserType.OPENAPI4J]
125+
}
126+
78127
void "throws when there are multiple global mappings for a simple type" () {
79128
def openApi = parse ("""\
80129
openapi: 3.0.2

0 commit comments

Comments
 (0)