Skip to content

Commit

Permalink
Revert "Workaround for duplicated anyOf"
Browse files Browse the repository at this point in the history
This reverts commit 3f0c735.
  • Loading branch information
jedrz committed Feb 25, 2025
1 parent 3f0c735 commit 8401e27
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import pl.touk.nussknacker.ui.process.test.ScenarioTestService.GenerateTestDataE
import pl.touk.nussknacker.ui.security.api.AuthManager
import pl.touk.nussknacker.ui.validation.ParametersValidator
import sttp.model.StatusCode.{BadRequest, NotFound}
import sttp.tapir.{Codec, CodecFormat, EndpointOutput, oneOfVariant, oneOfVariantFromMatchType, plainBody}
import sttp.tapir.EndpointIO.Example
import sttp.tapir.{Codec, CodecFormat, EndpointOutput, oneOfVariantFromMatchType, plainBody}

import scala.concurrent.{ExecutionContext, Future}

Expand Down Expand Up @@ -196,36 +197,66 @@ object TestingApiHttpService {

}

object ErrorOutputs {
object Examples {

val noScenarioErrorOutput: EndpointOutput.OneOfVariant[NoScenario] =
val noScenarioExample: EndpointOutput.OneOfVariant[NoScenario] =
oneOfVariantFromMatchType(
NotFound,
plainBody[NoScenario]
.example(
Example.of(
summary = Some("No scenario {scenarioName} found"),
value = NoScenario(ProcessName("'example scenario'"))
)
)
)

val noDataGeneratedErrorOutput: EndpointOutput.OneOfVariant[NoDataGenerated.type] =
oneOfVariant(
val noDataGeneratedExample: EndpointOutput.OneOfVariant[NoDataGenerated.type] =
oneOfVariantFromMatchType(
NotFound,
plainBody[NoDataGenerated.type]
.example(
Example.of(
summary = Some("No data was generated"),
value = NoDataGenerated
)
)
)

val noSourcesWithTestDataGenerationErrorOutput: EndpointOutput.OneOfVariant[NoSourcesWithTestDataGeneration.type] =
oneOfVariant(
val noSourcesWithTestDataGenerationExample: EndpointOutput.OneOfVariant[NoSourcesWithTestDataGeneration.type] =
oneOfVariantFromMatchType(
NotFound,
plainBody[NoSourcesWithTestDataGeneration.type]
.example(
Example.of(
summary = Some("No sources with test data generation available"),
value = NoSourcesWithTestDataGeneration
)
)
)

val tooManyCharactersGeneratedErrorOutput: EndpointOutput.OneOfVariant[TooManyCharactersGenerated] =
val tooManyCharactersGeneratedExample: EndpointOutput.OneOfVariant[TooManyCharactersGenerated] =
oneOfVariantFromMatchType(
BadRequest,
plainBody[TooManyCharactersGenerated]
.example(
Example.of(
summary = Some("Too many characters were generated"),
value = TooManyCharactersGenerated(length = 5000, limit = 2000)
)
)
)

val tooManySamplesRequestedErrorOutput: EndpointOutput.OneOfVariant[TooManySamplesRequested] =
val tooManySamplesRequestedExample: EndpointOutput.OneOfVariant[TooManySamplesRequested] =
oneOfVariantFromMatchType(
BadRequest,
plainBody[TooManySamplesRequested]
.example(
Example.of(
summary = Some("Too many samples requested"),
value = TooManySamplesRequested(maxSamples = 1000)
)
)
)

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import pl.touk.nussknacker.security.AuthCredentials
import pl.touk.nussknacker.ui.api.TapirCodecs.ScenarioGraphCodec._
import pl.touk.nussknacker.ui.api.TapirCodecs.ScenarioNameCodec._
import pl.touk.nussknacker.ui.api.TapirCodecs.ScenarioTestingCodecs._
import pl.touk.nussknacker.ui.api.TestingApiHttpService.ErrorOutputs.{
noDataGeneratedErrorOutput,
noScenarioErrorOutput,
noSourcesWithTestDataGenerationErrorOutput,
tooManyCharactersGeneratedErrorOutput,
tooManySamplesRequestedErrorOutput
import pl.touk.nussknacker.ui.api.TestingApiHttpService.Examples.{
noDataGeneratedExample,
noScenarioExample,
noSourcesWithTestDataGenerationExample,
tooManyCharactersGeneratedExample,
tooManySamplesRequestedExample
}
import pl.touk.nussknacker.ui.api.TestingApiHttpService.TestingError
import pl.touk.nussknacker.ui.definition.DefinitionsService
Expand Down Expand Up @@ -97,7 +97,7 @@ class TestingApiEndpoints(auth: EndpointInput[AuthCredentials]) extends BaseEndp
)
.errorOut(
oneOf[TestingError](
noScenarioErrorOutput,
noScenarioExample,
)
)
.withSecurity(auth)
Expand Down Expand Up @@ -133,7 +133,7 @@ class TestingApiEndpoints(auth: EndpointInput[AuthCredentials]) extends BaseEndp
)
.errorOut(
oneOf[TestingError](
noScenarioErrorOutput
noScenarioExample
)
)
.withSecurity(auth)
Expand Down Expand Up @@ -172,7 +172,7 @@ class TestingApiEndpoints(auth: EndpointInput[AuthCredentials]) extends BaseEndp
)
.errorOut(
oneOf[TestingError](
noScenarioErrorOutput
noScenarioExample
)
)
.withSecurity(auth)
Expand Down Expand Up @@ -204,11 +204,11 @@ class TestingApiEndpoints(auth: EndpointInput[AuthCredentials]) extends BaseEndp
)
.errorOut(
oneOf[TestingError](
noScenarioErrorOutput,
noDataGeneratedErrorOutput,
noSourcesWithTestDataGenerationErrorOutput,
tooManyCharactersGeneratedErrorOutput,
tooManySamplesRequestedErrorOutput,
noScenarioExample,
noDataGeneratedExample,
noSourcesWithTestDataGenerationExample,
tooManyCharactersGeneratedExample,
tooManySamplesRequestedExample,
)
)
.withSecurity(auth)
Expand Down
30 changes: 28 additions & 2 deletions docs-internal/api/nu-designer-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3259,6 +3259,10 @@ paths:
text/plain:
schema:
type: string
examples:
Example:
summary: No scenario {scenarioName} found
value: No scenario 'example scenario' found
'501':
description: Impersonation is not supported for defined authentication mechanism
content:
Expand Down Expand Up @@ -3360,6 +3364,10 @@ paths:
text/plain:
schema:
type: string
examples:
Example:
summary: No scenario {scenarioName} found
value: No scenario 'example scenario' found
'501':
description: Impersonation is not supported for defined authentication mechanism
content:
Expand Down Expand Up @@ -3433,7 +3441,14 @@ paths:
content:
text/plain:
schema:
type: string
anyOf:
- type: string
- type: string
examples:
Example:
summary: Too many samples requested
value: Too many samples requested, limit is 1000. Please configure
'testDataSettings.maxSamplesCount' to increase the limit
'401':
description: ''
content:
Expand Down Expand Up @@ -3462,7 +3477,14 @@ paths:
content:
text/plain:
schema:
type: string
anyOf:
- type: string
- type: string
- type: string
examples:
Example:
summary: No sources with test data generation available
value: No sources with test data generation available
'501':
description: Impersonation is not supported for defined authentication mechanism
content:
Expand Down Expand Up @@ -3581,6 +3603,10 @@ paths:
text/plain:
schema:
type: string
examples:
Example:
summary: No scenario {scenarioName} found
value: No scenario 'example scenario' found
'501':
description: Impersonation is not supported for defined authentication mechanism
content:
Expand Down

0 comments on commit 8401e27

Please sign in to comment.