Skip to content

Instantly share code, notes, and snippets.

@vikito755
vikito755 / merge-openapi-schemas.py
Last active May 13, 2025 05:10
Mergin OpenAPI schemas in Python.
# Intended for usage in Django DRF with DRF spectacular.
import yaml
import json
from pathlib import Path
from collections.abc import Mapping
import copy
from drf_spectacular.generators import SchemaGenerator
from drf_spectacular.views import SpectacularAPIView
from drf_spectacular.renderers import OpenApiJsonRenderer, OpenApiYamlRenderer
@vikito755
vikito755 / gist:c4180fcaf68f9c7908c9a738d852bcc2
Created March 23, 2023 12:41
TypeScript, replace the undefined values with null. Recursively.
export const replaceUndefinedWithNull = (obj: any) => {
for (let key in obj) {
if (obj.hasOwnProperty(key)) {
if (typeof obj[key] === "object") {
replaceUndefinedWithNull(obj[key]); // recursively call the function for nested objects
} else if (obj[key] === undefined) {
obj[key] = null;
}
}
}
@vikito755
vikito755 / Expiring mongo db document JS.
Created September 10, 2022 14:23
Expiring mongo db document using the Mongoose package in JavaScript. Guaranteed to work with Mongoose version 6.3.1.
// Record expires after 5 minutes.
const secondsBeforeExpiration = 300;
/* This works with the Mongoose package:
https://www.npmjs.com/package/mongoose */
const ExpiringSchema = new Schema({
Id: String,
initiatedAt: {
type: Date,
expires: secondsBeforeExpiration,