Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.NoSuchMethodError: io.swagger.models.properties.BaseIntegerProperty.getMinimum()Ljava/lang/Double; #234

Closed
zcb22000 opened this issue Jan 18, 2017 · 11 comments

Comments

@zcb22000
Copy link

zcb22000 commented Jan 18, 2017

I used java code to generate api and docs. But it is failed by throwing exception.

Swagger2Markup version:
1.2.0
Problem description:
It is the dependencies as bellow:

<dependency>
	<groupId>io.swagger</groupId>
	<artifactId>swagger-codegen</artifactId>
	<version>2.2.2</version>
	<scope>system</scope>
	<systemPath>${basedir}/lib/swagger-codegen-2.2.2-SNAPSHOT.jar</systemPath>
</dependency>
<dependency>
	<groupId>io.swagger</groupId>
	<artifactId>swagger-core</artifactId>
	<version>1.5.12</version>
</dependency>
<dependency>
	<groupId>io.swagger</groupId>
	<artifactId>swagger-parser</artifactId>
	<version>1.0.25</version>
</dependency>
<dependency>
	<groupId>io.swagger</groupId>
	<artifactId>swagger-compat-spec-parser</artifactId>
	<version>1.0.25</version>
</dependency>
<dependency>
	<groupId>com.samskivert</groupId>
	<artifactId>jmustache</artifactId>
	<version>1.13</version>
</dependency>
<dependency>
	<groupId>org.apache.commons</groupId>
	<artifactId>commons-lang3</artifactId>
	<version>3.5</version>
</dependency>
<dependency>
	<groupId>io.github.swagger2markup</groupId>
	<artifactId>swagger2markup</artifactId>
	<version>1.2.0</version>
</dependency>
<dependency>
	<groupId>nl.jworks.markdown_to_asciidoc</groupId>
	<artifactId>markdown_to_asciidoc</artifactId>
	<version>1.0</version>
	<scope>system</scope>
	<systemPath>${basedir}/lib/markdown_to_asciidoc-1.0.jar</systemPath>
</dependency>
<dependency>
	<groupId>io.github.swagger2markup</groupId>
	<artifactId>markup-document-builder</artifactId>
	<version>1.1.1</version>
	<scope>system</scope>
	<systemPath>${basedir}/lib/markup-document-builder-1.1.1.jar</systemPath>
</dependency>

it is failed. The exception is

Exception in thread "main" java.lang.NoSuchMethodError: io.swagger.models.properties.BaseIntegerProperty.getMinimum()Ljava/lang/Double;
	at io.github.swagger2markup.internal.adapter.PropertyAdapter.getMin(PropertyAdapter.java:240)
	at io.github.swagger2markup.internal.component.PropertiesTableComponent.lambda$apply$0(PropertiesTableComponent.java:97)
	at io.github.swagger2markup.internal.component.PropertiesTableComponent$$Lambda$23/105663489.accept(Unknown Source)
	at java.util.TreeMap.forEach(TreeMap.java:1001)
	at io.github.swagger2markup.internal.component.PropertiesTableComponent.apply(PropertiesTableComponent.java:84)
	at io.github.swagger2markup.internal.component.DefinitionComponent.typeSection(DefinitionComponent.java:160)
	at io.github.swagger2markup.internal.component.DefinitionComponent.apply(DefinitionComponent.java:80)
	at io.github.swagger2markup.internal.document.DefinitionsDocument.applyDefinitionComponent(DefinitionsDocument.java:160)
	at io.github.swagger2markup.internal.document.DefinitionsDocument.buildDefinition(DefinitionsDocument.java:138)
	at io.github.swagger2markup.internal.document.DefinitionsDocument.lambda$buildDefinitionsSection$0(DefinitionsDocument.java:102)
	at io.github.swagger2markup.internal.document.DefinitionsDocument$$Lambda$21/1100399456.accept(Unknown Source)
	at java.util.TreeMap.forEach(TreeMap.java:1001)
	at io.github.swagger2markup.internal.document.DefinitionsDocument.buildDefinitionsSection(DefinitionsDocument.java:99)
	at io.github.swagger2markup.internal.document.DefinitionsDocument.apply(DefinitionsDocument.java:86)
	at io.github.swagger2markup.Swagger2MarkupConverter.applyDefinitionsDocument(Swagger2MarkupConverter.java:203)
	at io.github.swagger2markup.Swagger2MarkupConverter.toFolder(Swagger2MarkupConverter.java:184)
@RobWin
Copy link
Member

RobWin commented Jan 18, 2017

Hi,

could you please try to use swagger-core:1.5.10.
Swagger2Markup uses swagger-core:1.5.10. swagger-core:1.5.12 seems to have some non backwards compatible changes.

@zcb22000
Copy link
Author

zcb22000 commented Jan 18, 2017

Thanks.
I have tried it with no exception. But it can't resolve $ref items which ref to other yaml file. The generator result is empty where used $ref.
My test code is

CodegenConfigurator configurator = CodegenConfigurator.fromFile(configFile);
new DefaultGenerator().opts(configurator.toClientOptInput()).generate();

Is there any mistake or options missing?

@RobWin
Copy link
Member

RobWin commented Jan 18, 2017

Sry, I don't use the CodegenConfigurator and swagger-codegen in general.

@zcb22000
Copy link
Author

use plugin?

@RobWin
Copy link
Member

RobWin commented Jan 18, 2017

Not sure what you mean?
Can you create a minimal project on GitHub so that I can reproduce your issue?

@zcb22000
Copy link
Author

OK,Thanks. How to upload my minimal project and where?

@RobWin
Copy link
Member

RobWin commented Jan 18, 2017

@zcb22000
Copy link
Author

zcb22000 commented Jan 19, 2017

Sorry, I can't upload my file for our network right setting.
My pom.xml:

	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>com.huawei.m2m.ecosystem.platform</groupId>
		<artifactId>rest-api</artifactId>
		<version>1.0.0</version>
	</parent>
	<artifactId>codegenerator</artifactId>

	<properties>
		<swagger-codegen.version>2.2.1</swagger-codegen.version>
	</properties>
	
	<dependencies>
		<dependency>
			<groupId>io.swagger</groupId>
			<artifactId>swagger-codegen</artifactId>
			<version>2.2.2</version>
			<scope>system</scope>
			<systemPath>${basedir}/lib/swagger-codegen-2.2.2-SNAPSHOT.jar</systemPath>
		</dependency>
		<dependency>
			<groupId>io.swagger</groupId>
			<artifactId>swagger-core</artifactId>
			<version>1.5.10</version>
		</dependency>
		<!-- <dependency>
			<groupId>io.swagger</groupId>
			<artifactId>swagger-parser</artifactId>
			<version>1.0.25</version>
		</dependency>
		<dependency>
			<groupId>io.swagger</groupId>
			<artifactId>swagger-codegen-cli</artifactId>
			<version>2.2.1</version>
		</dependency>
		<dependency>
			<groupId>io.swagger</groupId>
			<artifactId>swagger-compat-spec-parser</artifactId>
			<version>1.0.25</version>
		</dependency> -->
		<dependency>
			<groupId>com.samskivert</groupId>
			<artifactId>jmustache</artifactId>
			<version>1.13</version>
		</dependency>
		<dependency>
			  <groupId>org.apache.commons</groupId>
			  <artifactId>commons-lang3</artifactId>
			  <version>3.5</version>
		</dependency>
		<dependency>
			  <groupId>junit</groupId>
			  <artifactId>junit</artifactId>
			  <version>3.8.1</version>
			  <scope>test</scope>
		</dependency>

		<dependency>
			<groupId>org.apache.commons</groupId>
			<artifactId>commons-configuration2</artifactId>
			<version>2.0</version>
		</dependency>
		<dependency>
			<groupId>commons-beanutils</groupId>
			<artifactId>commons-beanutils</artifactId>
			<version>1.9.2</version>
		</dependency>
		<dependency>
			<groupId>org.apache.commons</groupId>
			<artifactId>commons-collections4</artifactId>
			<version>4.0</version>
		</dependency>
		<dependency>
			<groupId>org.pegdown</groupId>
			<artifactId>pegdown</artifactId>
			<version>1.6.0</version>
		</dependency>

		<dependency>
			<groupId>org.asciidoctor</groupId>
			<artifactId>asciidoctorj</artifactId>
			<version>1.5.4</version>
		</dependency>
		

		<dependency>
			<groupId>io.github.swagger2markup</groupId>
			<artifactId>swagger2markup</artifactId>
			<version>1.2.0</version>
		</dependency>
		<dependency>
			<groupId>nl.jworks.markdown_to_asciidoc</groupId>
			<artifactId>markdown_to_asciidoc</artifactId>
			<version>1.0</version>
			<scope>system</scope>
			<systemPath>${basedir}/lib/markdown_to_asciidoc-1.0.jar</systemPath>
		</dependency>
		<dependency>
			<groupId>io.github.swagger2markup</groupId>
			<artifactId>markup-document-builder</artifactId>
			<version>1.1.1</version>
			<scope>system</scope>
			<systemPath>${basedir}/lib/markup-document-builder-1.1.1.jar</systemPath>
		</dependency>
		<dependency>
			<groupId>org.apache.maven.shared</groupId>
			<artifactId>maven-invoker</artifactId>
			<version>2.2</version> <!-- see surefire-page for available versions -->
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<version>2.9</version>
			</plugin>
		</plugins>
	</build>

</project>```
my generator main method:
public static void main(String[] args) 
{
	System.out.println("start generate spring-cloud files");
	
	System.setProperty("models", "");
	System.setProperty("apis", "");
	System.setProperty("apiDocs", "true");


    generateFiles(NSCLConfig, "src/main/resources/yaml/index.yaml", "../target/doc/nscl/asciidoc");

}

private static void generateFiles(String configFile, String yamlFile, String asciidocFile)
{
	CodegenConfigurator configurator = CodegenConfigurator.fromFile(configFile);
	new DefaultGenerator().opts(configurator.toClientOptInput()).generate();

	Path localSwaggerFile = Paths.get(yamlFile);
	Path outputFile = Paths.get(asciidocFile);

	Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() 
			.withPathsGroupedBy(GroupBy.TAGS)
			.withOperationOrdering(OrderBy.NATURAL)
	        .withOutputLanguage(Language.ZH) 
	        .withMarkupLanguage(MarkupLanguage.ASCIIDOC)
	        .build(); 
	Swagger2MarkupConverter.from(localSwaggerFile) 
	        .withConfig(config)
	        .build() 
	        .toFolder(outputFile);; 
}

my index.yaml:

swagger: "2.0"

################################################################################

API Information

################################################################################
info:
version: "1.0.0"
title: REST API
termsOfService: used for Application developing

during dev, should point to your local machine

host: ip:port

basePath prefixes all resource paths

basePath: /myapp/v1.1.0

schemes:

tip: remove http to make production-grade

- http

  • https

format of bodies a client can send (Content-Type)

consumes:

  • application/json

format of the responses to the client (Accepts)

produces:

  • application/json

tags:

  • name: 订阅管理
    description: 订阅管理
  • name: 事件管理
    description: 事件管理

################################################################################

Security

################################################################################
securityDefinitions:
app_key:
type: apiKey
name: app_key
in: header
basic_auth:
type: basic
security:

  • app_key: []
  • basic_auth: []

paths:
$ref: ./paths/index.yaml

definitions:
$ref: './definitions/definitions.yaml#/definitions'

my paths/index.yaml file:

/subscriptions:
post:
operationId: addSubscriptions
tags:
- 订阅管理
x-isExistException: true
summary: 创建订阅
description: |
创建订阅
parameters:
-
name: subscriptionReq
in: body
description: 设置订阅的内容
required: true
schema:
$ref: '#/definitions/subscriptionReq'
responses:
200:
description: OK
schema:
$ref: '#/definitions/subscription'
400:
description: Bad Request
401:
description: Unauthorized
403:
description: Forbidden
404:
description: Not Found
500:
description: Server Error

@RobWin
Copy link
Member

RobWin commented Jan 19, 2017

Hi,

you can't split a Swagger file into several files like this.
See my issue in the swagger-parser library: swagger-api/swagger-parser#346

@RobWin
Copy link
Member

RobWin commented Jan 20, 2017

Can I close the issue?

@zcb22000
Copy link
Author

OK, Thanks a lot.

@RobWin RobWin closed this as completed Jan 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants