entur/schema2proto

schema2proto-maven-plugin: Cannot create property=customTypeReplacings + Unable to find property 'customTypeReplacings'

Closed this issue · 1 comments

eum2o commented

Hi, for me the schema2proto-maven-plugin fails with an error. Is this or bug or am I doing it wrong?

Environment

  • openjdk version "1.8.0_202"
  • Apache Maven 3.6.3
  • schema2proto-maven-plugin 1.40

Problem

I was trying to use the schema2proto-maven-plugin to generate a .proto file for a given .xsd file but got the following error:

[ERROR] Failed to execute goal no.entur:schema2proto-maven-plugin:1.40:generate (generate-resources) on project schema2proto-example: Execution generate-resources of goal no.entur:schema2proto-maven-plugin:1.40:generate failed: Cannot create property=customTypeReplacings for JavaBean=no.entur.schema2proto.generateproto.Schema2ProtoConfigFile@26f143ed
[ERROR]  in 'reader', line 2, column 1:
[ERROR]     outputFilename: generated-file.proto
[ERROR]     ^
[ERROR] Unable to find property 'customTypeReplacings' on class: no.entur.schema2proto.generateproto.Schema2ProtoConfigFile
[ERROR]  in 'reader', line 61, column 3:
[ERROR]       MessageTypeX: MessageTypeY
[ERROR]       ^

How to reproduce

  • Create a simple maven project with 2 resources aecfg.xsd and generateproto.yaml:

image

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>org.foobar</groupId>
	<artifactId>schema2proto-example</artifactId>
	<version>0.0.1-SNAPSHOT</version>

	<properties>
		<schema2proto.version>1.40</schema2proto.version>
	</properties>
	<build>
		<plugins>
			<plugin>
				<groupId>no.entur</groupId>
				<artifactId>schema2proto-maven-plugin</artifactId>
				<version>${schema2proto.version}</version>
				<configuration>
					<configFile>src/main/resources/generateproto.yaml</configFile>
					<xsdFile>src/main/resources/aecfg.xsd</xsdFile>
				</configuration>
				<executions>
					<execution>
						<id>generate-resources</id>
						<goals>
							<goal>generate</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project>

generateproto.yaml:

# Output proto file with this name. Only used when there is 1 file generated. Multiple XML namespaces give multiple files
outputFilename: generated-file.proto

# Target directory to write resulting proto files. Proto files are placed in sub folders according to their package name
outputDirectory: src/main/resources

# Include XSD annotation/documentation on message level
includeMessageDocs: true

# Include XSD annotation/documentation on field level
includeFieldDocs: true

# Add XSD file location as message/field comment as well. Useful when debugging where a particular field/message arised
includeSourceLocationInDoc: false

# Parse schema validation rules (minOccurs, maxOccurs, minLenght etc) from xsd and include them as proto validation rules using https://github.com/envoyproxy/protoc-gen-validate
includeValidationRules: false

# If true, each xsd extension base is treated as a field member of the parent type.
# Ie if structure is C extends B extends A, the resulting structure will be a message C with fields a and b referring respectively to message a and b.
#  Any elements or attributes declared in message a or be will be contained there.
# If false, all attributes and elements from all parents are added to the generated proto message.
inheritanceToComposition: false

# Any options that will be added to each proto file
options:
  java_package: org.entur.protobuf
  java_multiple_files: true

# Any extra imports added to each proto file. Must be used if referring to external types
customImports:
  - google/protobuf/timestamp.proto
  - google/protobuf/duration.proto
  - google/protobuf/any.proto

# Any extra import locations to use when the linker is trying to validate the generated proto files.
# Used in conjunction with customImports
customImportLocations:
  - pathToRootFolder1OfProtobufImport
  - pathToRootFolder2OfProtobufImport

# Ignore computed output fields. Note that the field name is the one used before converting to lower_case
ignoreOutputFields:
  - package.name/MessageName/FieldName

# Any type mappings to perform. Use this to either rename message types or to do replacement of default mappings from
# xml primitives to proto primitives. Regex supported.
# Since possibly several expressions may match, the declaration order is honoured
customTypeMappings:
  # Left side of colon (:) is replaced by right side.
  ^(.*)a$: $1b
  x: y

# Same as customTypeMappings except used for field names. Regex also supported here as well
customNameMappings:
  a: b
  x: y

# Replace given type with the new type. The new type must exist. Does not change message names, but only changes references to given message type
customTypeReplacings:
  MessageTypeX: MessageTypeY
  x: y

# If a type extends another type without adding any new fields, skip this type and
skipEmptyTypeInheritance: false

# Name and location of the proto.lock file produced by prototool https://github.com/nilslice/protolock (or the maven plugin). This is used to detect backwards incompatibilities
protoLockFile: proto.lock

# If possible backwards incompatibility is detected during parsing when protoLockFile has been specified, fail the conversion in order to allow manual intervention / verification.
# Setting `failIfRemovedFields: false` will print warnings but not fail the conversion. When using the Maven plugin you may also specify this as -DfailIfRemovedFields=false on the cmd line
failIfRemovedFields: true

# Support derivation by subsumption. See https://cs.au.dk/~amoeller/XML/schemas/xmlschema-inheritance.html under "Subsumption"
derivationBySubsumption: false

# Include 'go_package' options in all files
includeGoPackageOptions: false
goPackageSourcePrefix: xxx.github/go/

Build with
mvn package

eum2o commented

Sorry, my bad. I did not update the template/example file enough. After deleting some "placeholders" from generateproto.yaml it works.

(Feel free to delete this issue).