Skip to content

Commit

Permalink
Merge branch 'commercetools:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
demeyerthom authored Aug 12, 2024
2 parents ac5019e + 70e6c98 commit 16e1a59
Show file tree
Hide file tree
Showing 49 changed files with 1,371 additions and 212 deletions.
133 changes: 0 additions & 133 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,139 +6,6 @@ on:
name: AutoRelease

jobs:
# build-native:
# name: Build all native images
# continue-on-error: true
# strategy:
# matrix:
# include:
# - os: ubuntu-latest
# name: Linux
# artifact: rmf-codegen.linux
# - os: macos-latest
# name: Mac OS X
# artifact: rmf-codegen.darwin
# # TODO windows fails, reason not known yet
# # - os: windows-latest
# # name: Windows
# # artifact: rmf-codegen.win32
# runs-on: ${{ matrix.os }}
# steps:
# - name: Checkout
# uses: actions/checkout@v3
#
# - name: Setup Java
# uses: actions/setup-java@v3
# with:
# distribution: 'temurin'
# java-version: '11'
#
# - name: Build ${{ matrix.name }} native image
# uses: gradle/gradle-command-action@v1
# with:
# arguments: nativeImage
# build-root-directory: tools/cli-application
# gradle-executable: ./gradlew
#
# - name: Upload ${{ matrix.name }} native image
# uses: actions/upload-artifact@v1
# with:
# name: ${{ matrix.artifact }}
# path: ./tools/cli-application/build/graal/rmf-codegen
#
# release:
# name: Build JAR and Release the artifacts
# runs-on: ubuntu-latest
# needs: build-native
# steps:
# - name: Checkout
# uses: actions/checkout@v3
#
# - name: Setup Java
# uses: actions/setup-java@v3
# with:
# distribution: 'temurin'
# java-version: '11'
#
# - name: Build JAR
# uses: gradle/gradle-command-action@v1
# with:
# arguments: build
# build-root-directory: tools/cli-application
# gradle-executable: ./gradlew
#
# - name: Get current date
# id: date
# run: echo "::set-output name=date::$(date +'%Y-%m-%d_%H-%M-%S')"
#
# - name: Download native build artifacts
# uses: actions/download-artifact@v2
#
# - name: Commit new version to README and install script
# uses: stefanzweifel/[email protected]
# with:
# commit_message: "TASK: Updating version in README"
# commit_user_name: Auto Mation
# commit_user_email: [email protected]
# commit_author: Auto Mation <[email protected]>
#
# - name: Create GitHub Release
# id: create_github_release
# uses: actions/create-release@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# tag_name: ${{ github.ref }}
# release_name: ${{ github.ref }}
# draft: false
# prerelease: false
#
# - name: Upload JAR
# id: upload-release-asset
# uses: actions/upload-release-asset@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# upload_url: ${{ steps.create_github_release.outputs.upload_url }}
# asset_path: rmf-codegen.jar
# asset_name: rmf-codegen.jar
# asset_content_type: application/java-archive
#
# - name: Upload Linux Binary
# id: upload-linux-asset
# uses: actions/upload-release-asset@v1
# continue-on-error: true
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# upload_url: ${{ steps.create_github_release.outputs.upload_url }}
# asset_path: rmf-codegen.linux/rmf-codegen
# asset_name: rmf-codegen.linux
# asset_content_type: application/octet-stream
#
# - name: Upload Mac OS Binary
# id: upload-mac-asset
# continue-on-error: true
# uses: actions/upload-release-asset@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# upload_url: ${{ steps.create_github_release.outputs.upload_url }}
# asset_path: rmf-codegen.darwin/rmf-codegen
# asset_name: rmf-codegen.darwin
# asset_content_type: application/octet-stream

# - name: Upload Windows Binary
# id: upload-windows-asset
# uses: actions/upload-release-asset@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# upload_url: ${{ steps.create_github_release.outputs.upload_url }}
# asset_path: rmf-codegen.win32/rmf-codegen
# asset_name: rmf-codegen.exe
# asset_content_type: application/octet-stream

release_maven:
name: Build and release to Maven

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ fun AnyType.deprecated() : Boolean {
val anno = this.getAnnotation("deprecated")
return (anno != null && (anno.value as BooleanInstance).value)
}

fun AnyType.markDeprecated() : Boolean {
val anno = this.getAnnotation("markDeprecated")
return (anno != null && (anno.value as BooleanInstance).value)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.commercetools.rmf.validators

import io.vrap.rmf.raml.model.modules.util.ModulesSwitch
import io.vrap.rmf.raml.model.resources.util.ResourcesSwitch
import io.vrap.rmf.raml.model.types.AnnotationsFacet
import io.vrap.rmf.raml.model.types.ArrayInstance
import io.vrap.rmf.raml.validation.AbstractRamlValidator
import io.vrap.rmf.raml.validation.RamlValidator
import org.eclipse.emf.common.util.Diagnostic
Expand All @@ -19,7 +21,13 @@ class ModulesValidator(private val validators: List<ModulesSwitch<List<Diagnosti
context: MutableMap<Any, Any>?
): Boolean {
val validationResults = validators.stream()
.flatMap { validator: ModulesSwitch<List<Diagnostic>> -> validator.doSwitch(eObject).stream() }
.flatMap { validator: ModulesSwitch<List<Diagnostic>> ->
return@flatMap if (eObject is AnnotationsFacet && eObject.getAnnotation("ignoreValidators") != null && (eObject.getAnnotation("ignoreValidators").value as ArrayInstance).value.any { it.value == validator.javaClass.simpleName } ) {
emptyList<Diagnostic>().stream()
} else {
validator.doSwitch(eObject).stream()
}
}
.collect(Collectors.toList())
validationResults.forEach(Consumer { diagnostic: Diagnostic? -> diagnostics.add(diagnostic) })
return validationResults.isEmpty()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.commercetools.rmf.validators

import io.vrap.rmf.raml.model.modules.Library
import io.vrap.rmf.raml.model.types.AnyType
import io.vrap.rmf.raml.model.types.BuiltinType
import io.vrap.rmf.raml.model.types.ObjectType
import io.vrap.rmf.raml.model.types.TypeTemplate
import org.eclipse.emf.common.util.Diagnostic
import java.util.*

//@ValidatorSet
class PolymorphicSubtypesRule(severity: RuleSeverity, options: List<RuleOption>? = null) : TypesRule(severity, options) {

private val exclude: List<String> =
(options?.filter { ruleOption -> ruleOption.type.lowercase(Locale.getDefault()) == RuleOptionType.EXCLUDE.toString() }?.map { ruleOption -> ruleOption.value }?.plus("") ?: defaultExcludes)

override fun caseAnyType(type: AnyType): List<Diagnostic> {
val validationResults: MutableList<Diagnostic> = ArrayList()

if (exclude.contains(type.name).not() && type is ObjectType && type.subTypes.filterNot { it.isInlineType }.any() && type.discriminator == null) {
validationResults.add(create(type, "Type \"{0}\" has subtypes but no discriminator is set", type.name))
}
return validationResults
}

companion object : ValidatorFactory<PolymorphicSubtypesRule> {
private val defaultExcludes by lazy { listOf("") }

@JvmStatic
override fun create(options: List<RuleOption>?): PolymorphicSubtypesRule {
return PolymorphicSubtypesRule(RuleSeverity.ERROR, options)
}

@JvmStatic
override fun create(severity: RuleSeverity, options: List<RuleOption>?): PolymorphicSubtypesRule {
return PolymorphicSubtypesRule(severity, options)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class QueryParameterCamelCaseRule(severity: RuleSeverity, options: List<RuleOpti
if (exclude.contains(queryParameter.name).not() && queryParameter.pattern == null) {
if (!queryParameter.name.matches(Regex("^[.a-zA-Z0-9]+$"))) {
validationResults.add(create(queryParameter, "Query parameter \"{0}\" name must use alphanum and dot only", queryParameter.name))
} else if (StringCaseFormat.LOWER_CAMEL_CASE.apply(queryParameter.name) != queryParameter.name) {
} else if (StringCaseFormat.LOWER_CAMEL_CASE.apply(queryParameter.name.replace(".", "")) != queryParameter.name.replace(".", "")) {
validationResults.add(create(queryParameter, "Query parameter \"{0}\" must be lower camel cased", queryParameter.name))
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.commercetools.rmf.validators

import io.vrap.rmf.raml.model.resources.util.ResourcesSwitch
import io.vrap.rmf.raml.model.types.AnnotationsFacet
import io.vrap.rmf.raml.model.types.ArrayInstance
import io.vrap.rmf.raml.validation.AbstractRamlValidator
import io.vrap.rmf.raml.validation.RamlValidator
import io.vrap.rmf.raml.validation.ResolvedRamlValidator
Expand All @@ -20,7 +22,13 @@ class ResolvedResourcesValidator(private val validators: List<ResourcesSwitch<Li
context: Map<Any, Any>
): Boolean {
val validationResults = validators.stream()
.flatMap { validator: ResourcesSwitch<List<Diagnostic>> -> validator.doSwitch(eObject).stream() }
.flatMap { validator: ResourcesSwitch<List<Diagnostic>> ->
return@flatMap if (eObject is AnnotationsFacet && eObject.getAnnotation("ignoreValidators") != null && (eObject.getAnnotation("ignoreValidators").value as ArrayInstance).value.any { it.value == validator.javaClass.simpleName } ) {
emptyList<Diagnostic>().stream()
} else {
validator.doSwitch(eObject).stream()
}
}
.collect(Collectors.toList())
validationResults.forEach(Consumer { diagnostic: Diagnostic? -> diagnostics.add(diagnostic) })
return validationResults.isEmpty()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.commercetools.rmf.validators

import io.vrap.rmf.raml.model.resources.util.ResourcesSwitch
import io.vrap.rmf.raml.model.types.AnnotationsFacet
import io.vrap.rmf.raml.model.types.ArrayInstance
import io.vrap.rmf.raml.validation.AbstractRamlValidator
import io.vrap.rmf.raml.validation.RamlValidator
import org.eclipse.emf.common.util.Diagnostic
Expand All @@ -19,7 +21,13 @@ class ResourcesValidator(private val validators: List<ResourcesSwitch<List<Diagn
context: Map<Any, Any>
): Boolean {
val validationResults = validators.stream()
.flatMap { validator: ResourcesSwitch<List<Diagnostic>> -> validator.doSwitch(eObject).stream() }
.flatMap { validator: ResourcesSwitch<List<Diagnostic>> ->
return@flatMap if (eObject is AnnotationsFacet && eObject.getAnnotation("ignoreValidators") != null && (eObject.getAnnotation("ignoreValidators").value as ArrayInstance).value.any { it.value == validator.javaClass.simpleName } ) {
emptyList<Diagnostic>().stream()
} else {
validator.doSwitch(eObject).stream()
}
}
.collect(Collectors.toList())
validationResults.forEach(Consumer { diagnostic: Diagnostic? -> diagnostics.add(diagnostic) })
return validationResults.isEmpty()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.commercetools.rmf.validators

import io.vrap.rmf.raml.model.resources.util.ResourcesSwitch
import io.vrap.rmf.raml.model.types.AnnotationsFacet
import io.vrap.rmf.raml.model.types.ArrayInstance
import io.vrap.rmf.raml.model.types.util.TypesSwitch
import io.vrap.rmf.raml.validation.AbstractRamlValidator
import io.vrap.rmf.raml.validation.RamlValidator
Expand All @@ -20,7 +21,13 @@ class TypesValidator(private val validators: List<TypesSwitch<List<Diagnostic>>>
context: Map<Any, Any>
): Boolean {
val validationResults = validators.stream()
.flatMap { validator: TypesSwitch<List<Diagnostic>> -> validator.doSwitch(eObject).stream() }
.flatMap { validator: TypesSwitch<List<Diagnostic>> ->
return@flatMap if (eObject is AnnotationsFacet && eObject.getAnnotation("ignoreValidators") != null && (eObject.getAnnotation("ignoreValidators").value as ArrayInstance).value.any { it.value == validator.javaClass.simpleName } ) {
emptyList<Diagnostic>().stream()
} else {
validator.doSwitch(eObject).stream()
}
}
.collect(Collectors.toList())
validationResults.forEach(Consumer { diagnostic: Diagnostic? -> diagnostics.add(diagnostic) })
return validationResults.isEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,14 @@ class ValidatorRulesTest extends Specification implements ValidatorFixtures {
result.validationResults[0].message == "Property \"/invalid/\" must define object type for placeholder annotation"
}

def "subtypes should be discriminated"() {
when:
def validators = Arrays.asList(new TypesValidator(Arrays.asList(PolymorphicSubtypesRule.create(emptyList()))))
def uri = uriFromClasspath("/polymorphic-subtype-rule.raml")
def result = new RamlModelBuilder(validators).buildApi(uri)
then:
result.validationResults.size == 1
result.validationResults[0].message == "Type \"InvalidBaz\" has subtypes but no discriminator is set"
}

}
38 changes: 38 additions & 0 deletions ctp-validators/src/test/resources/polymorphic-subtype-rule.raml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#%RAML 1.0
title: discriminator subtype rule

types:
Foo:
type: object
discriminator: type
properties:
type: string
SubFoo:
discriminatorValue: sub
type: Foo
Bar:
type: object
description: InvalidBar
properties:
name: string
FooBar:
description: FooBar
type: object
properties:
bar: Bar
FooBar2:
type: object
properties:
bar:
description: Bar
type: Bar
InvalidBaz:
type: object
description: InvalidBar
properties:
name: string
SubBaz:
description: SubBaz
type: InvalidBaz
SubBaz2:
type: InvalidBaz
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ext {
javaxValidation: '2.0.1.Final',
kotlin: kotlinVersion,
picocli: '4.6.1',
rmf: '0.2.0-20240119124459',
rmf: '0.2.0-20240722205528',
rxjava: '3.1.2',
slf4j: '1.7.25',
spock: '2.2-groovy-4.0',
Expand Down
8 changes: 8 additions & 0 deletions languages/bruno/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

dependencies {
implementation project(':codegen-renderers')
implementation commons.lang3
implementation commons.text
implementation orgkotlin.reflect
implementation orgkotlin.stdlib
}
Loading

0 comments on commit 16e1a59

Please sign in to comment.