mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-15 02:54:06 +02:00
# Description of Changes - **What was changed** - Updated controller methods to use strongly‐typed primitives (`int`, `long`, `boolean`) instead of `String` for numeric and boolean parameters, eliminating calls to `Integer.parseInt`/`Long.parseLong` and improving null‐safety (`Boolean.TRUE.equals(...)`). - Enhanced all API request model classes with richer Swagger/OpenAPI annotations: added `requiredMode`, `defaultValue`, `allowableValues`, `format`, `pattern`, and tightened schema descriptions for all fields. - Refactored HTML form templates for “Remove Blank Pages” to include `min`, `max`, and `step` attributes on numeric inputs, matching the updated validation rules. - **Why the change was made** - **Type safety & robustness**: Shifting from `String` to native types prevents runtime parsing errors, simplifies controller logic, and makes default values explicit. - **Better API documentation & validation**: Enriching the Swagger annotations ensures generated docs accurately reflect required fields, default values, and permitted ranges, which improves client code generation and developer experience. - **Consistency across codebase**: Aligning all request models and controllers enforces a uniform coding style and reduces bugs. #3406 --- ## Checklist ### General - [x] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [x] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md) (if applicable) - [x] I have performed a self-review of my own code - [x] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details.
35 lines
1.1 KiB
Java
35 lines
1.1 KiB
Java
package stirling.software.SPDF.model.api;
|
|
|
|
import java.util.List;
|
|
|
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
|
|
|
import io.swagger.v3.oas.annotations.Hidden;
|
|
import io.swagger.v3.oas.annotations.media.Schema;
|
|
import io.swagger.v3.oas.annotations.media.Schema.RequiredMode;
|
|
|
|
import lombok.Data;
|
|
import lombok.EqualsAndHashCode;
|
|
|
|
import stirling.software.SPDF.utils.GeneralUtils;
|
|
|
|
@Data
|
|
@EqualsAndHashCode(callSuper = true)
|
|
public class PDFWithPageNums extends PDFFile {
|
|
|
|
@Schema(
|
|
description =
|
|
"The pages to select, Supports ranges (e.g., '1,3,5-9'), or 'all' or functions in the"
|
|
+ " format 'an+b' where 'a' is the multiplier of the page number 'n', and 'b' is a"
|
|
+ " constant (e.g., '2n+1', '3n', '6n-5')",
|
|
defaultValue = "all",
|
|
requiredMode = RequiredMode.REQUIRED)
|
|
private String pageNumbers;
|
|
|
|
@Hidden
|
|
public List<Integer> getPageNumbersList(PDDocument doc, boolean oneBased) {
|
|
int pageCount = doc.getNumberOfPages();
|
|
return GeneralUtils.parsePageList(pageNumbers, pageCount, oneBased);
|
|
}
|
|
}
|