-
Notifications
You must be signed in to change notification settings - Fork 96
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
Add ability to set project directory. #1115
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,9 @@ | |
import io.swagger.v3.oas.models.Components; | ||
import io.swagger.v3.oas.models.OpenAPI; | ||
|
||
import static io.micronaut.openapi.visitor.OpenApiApplicationVisitor.MICRONAUT_INTERNAL_OPENAPI_PROJECT_DIR; | ||
import static io.micronaut.openapi.visitor.OpenApiApplicationVisitor.MICRONAUT_OPENAPI_PROJECT_DIR; | ||
|
||
/** | ||
* Some util methods. | ||
* | ||
|
@@ -92,14 +95,28 @@ private Utils() { | |
|
||
@Nullable | ||
public static Path getProjectPath(VisitorContext context) { | ||
Path path; | ||
try { | ||
path = context.getProjectDir().orElse(Utils.isTestMode() ? Paths.get(System.getProperty("user.dir")) : null); | ||
} catch (Exception e) { | ||
// Should never happen | ||
path = Paths.get(System.getProperty("user.dir")); | ||
|
||
Path projectPath = context.get(MICRONAUT_INTERNAL_OPENAPI_PROJECT_DIR, Path.class).orElse(null); | ||
if (projectPath != null) { | ||
return projectPath; | ||
} | ||
|
||
String projectDir = System.getProperty(MICRONAUT_OPENAPI_PROJECT_DIR); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you shouldn't use system properties but the annotation processor options otherwise the compiler can't detect when input values change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't quite understand what's wrong here. As I understand it, it is necessary to describe the properties of the processor, which must be allowed to be loaded as system variables. They are described in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in general parameters to an annotation processor should never be ready from system properties and should always be read from annotation processor arguments, this particular processor abuses that badly in several places which is less than ideal. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, then how is it correct to write the reading of the arguments? Although I'm not sure if there's much to worry about using system variables. I think it's redundant There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @graemerocher Do I need to write something like this? context.getOptions().get(MICRONAUT_INTERNAL_OPENAPI_PROJECT_DIR) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's just that I don't understand. I give kapt the annotation processor argument, but I read it with a system property. That is, it turns out that all arguments are already available as system properties. Or does kapt set not an argument, but a system property? I tested this solution on a test project - it works correctly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes it needs to be |
||
if (projectDir != null) { | ||
projectPath = Paths.get(projectDir); | ||
} | ||
return path; | ||
if (projectPath == null) { | ||
try { | ||
projectPath = context.getProjectDir().orElse(Utils.isTestMode() ? Paths.get(System.getProperty("user.dir")) : null); | ||
} catch (Exception e) { | ||
// Should never happen | ||
projectPath = Paths.get(System.getProperty("user.dir")); | ||
} | ||
} | ||
|
||
context.put(MICRONAUT_INTERNAL_OPENAPI_PROJECT_DIR, projectPath); | ||
|
||
return projectPath; | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
If you wish to expose the generated OpenAPI yaml output from your running application you can simply add the necessary static resource to the application configuration. For example: | ||
|
||
.Exposing OpenAPI YAML | ||
[source,yaml] | ||
[configuration] | ||
---- | ||
micronaut: | ||
router: | ||
static-resources: | ||
swagger: | ||
paths: classpath:META-INF/swagger | ||
mapping: /swagger/** | ||
router: | ||
static-resources: | ||
swagger: | ||
paths: classpath:META-INF/swagger | ||
mapping: /swagger/** | ||
---- | ||
|
||
With the above configuration in place when you run your application you can access your Swagger documentation at `http://localhost:8080/swagger/hello-world-0.0.yml`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
To support incremental annotation processing, you need to explicitly set the path to | ||
the project directory through the annotation processor setting `micronaut.openapi.project.dir` like this: | ||
|
||
.Gradle | ||
[source,groovy] | ||
``` | ||
kapt { | ||
arguments { | ||
arg("micronaut.openapi.project.dir", projectDir) | ||
} | ||
} | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ public class ApiController { | |
} | ||
---- | ||
|
||
[source,yaml] | ||
[configuration] | ||
---- | ||
micronaut: | ||
openapi: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you override
getSupportedOptions()
and provide all of these constants as annotation processor optionsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand, this block do the same