Skip to content

Commit

Permalink
W-13992415: fix oas to oas nullable parameter emission
Browse files Browse the repository at this point in the history
  • Loading branch information
arielmirra committed Oct 30, 2023
1 parent a238267 commit a773cea
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,8 @@ case class OasParametersEmitter(
}

def emitters(): Seq[EntryEmitter] = {
val results = ListBuffer[EntryEmitter]()
val (oasParameters, ramlParameters) =
parameters.partition(p =>
Option(p.schema).isEmpty || p.schema.isInstanceOf[ScalarShape] || p.schema
.isInstanceOf[ArrayShape] || p.schema.isInstanceOf[FileShape]
)
val results = ListBuffer[EntryEmitter]()
val (oasParameters, ramlParameters) = parameters.partition(isValidOasParam)

if (oasParameters.nonEmpty || payloads.nonEmpty)
results += OasParameterEmitter(oasParameters, references)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"openapi": "3.0.0",
"info": {
"title": "API",
"version": "1.0.0"
},
"paths": {
"/customers": {
"get": {
"parameters": [
{
"in": "query",
"name": "enterpriseCustomerNumber",
"schema": {
"nullable": true,
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
openapi: 3.0.3
info:
title: API
version: 1.0.0

paths:
/customers:
get:
parameters:
- in: query
name: enterpriseCustomerNumber
schema:
nullable: true
type: string
responses:
'200':
description: OK
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
openapi: 3.0.3
info:
title: API
version: 1.0.0

paths:
/customers:
get:
parameters:
- in: query
name: enterpriseCustomerNumber
schema:
nullable: true
type: string
responses:
'200':
description: OK
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import amf.core.client.scala.errorhandling.UnhandledErrorHandler
import amf.core.client.scala.model.document.BaseUnit
import amf.core.client.scala.parse.AMFParser
import amf.core.client.scala.transform.AMFTransformer
import amf.core.internal.remote.{Hint, Oas30YamlHint, Raml10YamlHint}
import amf.core.internal.remote.{Hint, Oas30JsonHint, Oas30YamlHint, Raml10YamlHint}
import amf.core.internal.resource.StringResourceLoader
import amf.io.FileAssertionTest
import org.scalatest.Assertion
Expand Down Expand Up @@ -39,6 +39,15 @@ class CompatibilityCycleTest extends AsyncFunSuite with FileAssertionTest {
)
}

test("OAS 3.0 with nullable parameter to JSON") {
compatibility(
"oas30/nullable-query-param.yaml",
"oas30/nullable-query-param.json",
Oas30YamlHint,
Oas30JsonHint
)
}

/** Compile source with specified hint. Render to temporary file and assert against golden. */
private def compatibility(source: String, golden: String, from: Hint, to: Hint): Future[Assertion] = {
for {
Expand Down

0 comments on commit a773cea

Please sign in to comment.