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

jsonschema-maven-plugin: add deleteExistingSchemas #501

Open
nimo23 opened this issue Dec 9, 2024 · 8 comments
Open

jsonschema-maven-plugin: add deleteExistingSchemas #501

nimo23 opened this issue Dec 9, 2024 · 8 comments

Comments

@nimo23
Copy link

nimo23 commented Dec 9, 2024

Please add an an option for jsonschema-maven-plugin:

deleteExistingSchemas: true|false:
If true, existing schemas within the defined SchemaFilePath are deleted before new ones are generated.

Example:

<plugin>
    <groupId>com.github.victools</groupId>
    <artifactId>jsonschema-maven-plugin</artifactId>
    <version>${jsonschema.version}</version>
    <executions>
        <execution>
        <?m2e ignore?>
        <goals>
            <goal>generate</goal>
        </goals>
        </execution>
    </executions>
    <configuration>
        <schemaFilePath>src/main/resources/schemas</schemaFilePath>

        <!-- missing configuration property -->
        <deleteExistingFiles>true</deleteExistingFiles>
..
</plugin>

Currently it seems that only existing files are overwritten and already generated schemas remain untouched (even if classNames or packageNames have been changed).

@CarstenWickner
Copy link
Member

Hi @nimo23,

Is the Maven clean command not cleaning it up for you? That would be the standard approach in my view.
If the Maven plugin didn't discard the whole directory, it would be hard-pressed to pick the exact files to delete.
If it can be avoided, I'd rather not add this to the plugin directly.

However, if there is no other way, I'm open to pull requests to include the extra parameter.

@nimo23
Copy link
Author

nimo23 commented Dec 9, 2024

Is the Maven clean command not cleaning it up for you? That would be the standard approach in my view.

Having someting like

<schemaFilePath>src/main/resources/schemas</schemaFilePath>

will not be cleaned by maven clean because it's a directory within src/main/resources/. The clean will only clean files from the target-directory.

it would be hard-pressed to pick the exact files to delete.

No need to pick the exact files to delete. It is enough just to delete all the content (with subfolders) in the specified folder (in this example: src/main/resources/schemas).

@CarstenWickner
Copy link
Member

Hi @nimo23,

How about assigning a dedicated directory for the generated schema files, that can then be targeted by the clean command?

Or use something like the following to get rid of this particular directory's contents too?

<plugin>
    <artifactId>maven-clean-plugin</artifactId>
    <version>2.6.1</version>
    <configuration>
        <filesets>
            <fileset>
                <directory>src/main/resources/schemas</directory>
                <includes>
                    <include>**/*</include>
                </includes>
            </fileset>
        </filesets>
    </configuration>
</plugin>

@nimo23
Copy link
Author

nimo23 commented Dec 9, 2024

How about assigning a dedicated directory for the generated schema files, that can then be targeted by the clean command?

Sure. This works. However, this needs to be set up by the user. Normally, the user expects that previously generated files from jsonschema-maven-plugin that are not listed in its configuration-tag will be automatically deleted.
It could at least be documented that previously generated files are not automatically deleted and the user must use the maven-clean plugin if he wants to delete such obsolete files.

@CarstenWickner
Copy link
Member

I don't quite agree with that expectation.
If you want them to be removed each time, then the target folder is the right place for the schema files.
Putting them in the main folder indicates, that they are supposed to remain there.
Alternatively, a dedicated generated folder for such files, that would also be cleaned-up automatically.

It boils down to the folder selection, whether the old schema files get discarded or not.

@nimo23
Copy link
Author

nimo23 commented Dec 9, 2024

If you want them to be removed each time, then the target folder is the right place for the schema files.

Yes, but imagine that the consuming client side framework has a folder within src/main/webapp/jsonschema, then the user must delete those files while developing because jsonschema-maven-plugin does not care of stale schema generated files.

@CarstenWickner
Copy link
Member

Yes, I understand that occasionally the need for clearing the target arises. E.g., when you cannot just put the generated files in the mirrored target/main/webapp/jsonschema folder.

My opinion still holds though. Even the compiler plugin does not delete old compiled files itself. That's what the clean command is responsible for. It is consistent to do the same here.
If there are additional folders to be cleaned up, that's to be configured on the plugin that performs such clean-ups.

@nimo23
Copy link
Author

nimo23 commented Dec 10, 2024

Even the compiler plugin does not delete old compiled files itself. That's what the clean command is responsible for.

Would it be possible for the plugin to call this cleanup step if deleteExistingSchemas=true? If not, then at least it could be documented that the plugin does not remove obsolete files itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants